473,386 Members | 2,129 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,386 software developers and data experts.

Main class constructor !

I am new to Java.

Since the "main" class has the main() function it it, is this called
before the constructor, or is a constructor totally irrelevant for a
main class, since you never "new" it ?
I am used to C++ whare main exists outside any class.

I have a test "main" class and it appears the constructor is never
called ?

Confused !

TIA
Remove the SPAMBLOCK from my email address to reply.
Jul 17 '05 #1
2 7588
Alan.J.Thackray wrote:
I am new to Java.

Since the "main" class has the main() function it it, is this called
before the constructor, or is a constructor totally irrelevant for a
main class, since you never "new" it ?
I am used to C++ whare main exists outside any class.

I have a test "main" class and it appears the constructor is never
called ?


That is correct. Note that main() is declared static. In this context,
static means the same as it does in C++; a static method does not need
to be invoked on an instance of a class.

Many people who wish to stay in the OO paradigm will write main()
similar to the following:

public class MyClass
{
// ...other code...

public static void main(String args[])
{
final MyClass myInstance = new MyClass();
myInstance.go();
}
}

HTH,
Ray

--
XML is the programmer's duct tape.
Jul 17 '05 #2

"Alan.J.Thackray" <al*************@SPAMBLOCK.blueyonder.co.uk> wrote in
message news:jq********************************@4ax.com...
I am new to Java.

Since the "main" class has the main() function it it, is this called
before the constructor, or is a constructor totally irrelevant for a
main class, since you never "new" it ?
I am used to C++ whare main exists outside any class.

I have a test "main" class and it appears the constructor is never
called ?

Confused !

TIA


Sounds like you actually named your class "main" ????
You should steer clear of class names like that to avoid confusion.
Name a class "Bill" or "George" - even "Sue" - use proper case to follow
convention, and keep away from reserved words.
--- main is a static method, which means you do not need to create an
instance of that class to run the method.
main is *not* a constructor, its a special method.
HTH

---
Outgoing mail is certified Virus Free.
Checked by AVG anti-virus system (http://www.grisoft.com).
Version: 6.0.807 / Virus Database: 549 - Release Date: 12/7/2004
Jul 17 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

5
by: Henry Jordon | last post by:
hello I was wondering if someone could help me get a main going on this project I've completed the header file that the professor started us on but not really sure how to get the main going. If...
4
by: wongjoekmeu | last post by:
Hello All, >From a book where I have learned C++ it says that each application must have at least one function which is the main() function. Now I have the source code of a C++ program from...
6
by: Marc | last post by:
I am just starting out teaching myself C#, and I have come accross a confusing point in my book. It seems that any class can have a Main() function, but what does that mean? Is the Main() function...
2
by: Bill D | last post by:
In a simple Windows forms application, the main form is called Form1. Within this form's class, I refer to the the running instance of this main class as "this" as in this.Text = "NEW TEXT" I...
1
by: BillZondlo | last post by:
Can someone look at this and tell me why, when I call this from my main app, it displays fine (fades form in and out) but then before my main app displays, I see other dialog boxes flash...
2
by: Legendary Pansy | last post by:
Hello, I'm trying to accomplish the impossible by trying to do something equivalent of this example found here http://www.c-sharpcorner.com/Code/2003/Dec/DialogTutorial.as Starting with "Listing...
2
by: Defected | last post by:
Hi, How i can implement a main function with this Binary Search Tree. thanks for help. is this code corrected ? #include<iostream>
3
by: Jon | last post by:
My main form opens up another form, and from this other form, I'd like to access things in the main form. The problem is that although I know the name of the class of the main form (FormMain) I...
4
by: lilyumestar | last post by:
I have project I have to do for class. We have to write 4 different .java files. Project2.java HouseGUI.java House.java HouseSorting.java I already finish House.java and I need to work on...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.