[HENRY: Added Code Tags] [ August 15, 2008: Message edited by: Henry Wong ]
nitin ratra
Greenhorn
Joined: Aug 11, 2008
Posts: 25
posted
0
What is wrong in this code ? Actually I thinking I have done some errors in accessing the static method inside the main method. SO people how do I acess the non static method inside main method?
Actually I want to access the Iday
Richard Bradford
Ranch Hand
Joined: Apr 20, 2004
Posts: 48
posted
0
There are a few things wrong.
Firstly, you can't access the non static methods directly from main. Instead create your Independence instance within the main method (check the variable assignment in your constructor its the wrong way round) and call its Iday method. [ August 15, 2008: Message edited by: Richard Bradford ]
I think what Richard mentioned, is that the first problem appears to lie with your constructor.
you have
when it should be:
Also I guess by your Class name, you are Indian? If so, may I wish you a very Happy Idependence day! Jai Hind!
be a well encapsulated person, don't expose your privates, unless you public void getWife()!
nitin ratra
Greenhorn
Joined: Aug 11, 2008
Posts: 25
posted
0
thanks friend for taking keen intrest in my problem and thanks for wishiing mee independence day , yes I am an Indian
nitin ratra
Greenhorn
Joined: Aug 11, 2008
Posts: 25
posted
0
It must be a very simple question , but I want to ask it if you pepole can explain mee. I can provide a constructor to my class but actually I don't know what a constructor does? I have read sun tutorial,but actually I can't get the real picture fo it . Please if I can get something about constructor. I know it is a foolish type question but please if I get some knoledge of it. regards Nitin
Satya Maheshwari
Ranch Hand
Joined: Jan 01, 2007
Posts: 368
posted
0
One way of looking constructor is to consider it as a suitable place where you can write code which needs to be executed whenever an object of that class is intantiated. The code should usually be doing the initialization stuff for that object.
Thanks and Regards
Campbell Ritchie
Sheriff
Joined: Oct 13, 2005
Posts: 32638
4
posted
0
Originally posted by Satya Maheshwari:
One way of looking constructor is to consider it as a suitable place where you can write code which needs to be executed whenever an object of that class is intantiated. The code should usually be doing the initialization stuff for that object.
Be bold, Maheshwari!
The constructor is where you initialise the object. Not "should" or "usually." For the beginner, let's think of that as "always." [There are other ways to initialise objects, like factory methods, but let's look on them as more advanced than we need here.]
Every field has a default value when it is declared, but that is usually not suitable for real-life use, so you initialise them to "real" values in the constructor.
Nitin: who is teaching you programming? Have you got a course of any sort?
Satya Maheshwari
Ranch Hand
Joined: Jan 01, 2007
Posts: 368
posted
0
Be bold, Maheshwari!
With experts all around the ranch, one never knows when one has put himself in a spot.
Arijit Daripa
Ranch Hand
Joined: Aug 09, 2008
Posts: 142
posted
0
Nitin! your code should look like this
[ August 15, 2008: Message edited by: ARIJIT DARIPA ]
SCJP 5
nitin ratra
Greenhorn
Joined: Aug 11, 2008
Posts: 25
posted
0
Thanks to all members .
Campbell Ritchie
Sheriff
Joined: Oct 13, 2005
Posts: 32638
4
posted
0
You're welcome.
Please remember about titles for threads in future.
I agree. Here's the link: http://ej-technologies/jprofiler - if it wasn't for jprofiler, we would need to
run our stuff on 16 servers instead of 3.