File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Beginning Java and the fly likes code problem Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "code problem" Watch "code problem" New topic
Author

code problem

nitin ratra
Greenhorn

Joined: Aug 11, 2008
Posts: 25
hello, everyone I have a doubt ?



[HENRY: Added Code Tags]
[ August 15, 2008: Message edited by: Henry Wong ]
nitin ratra
Greenhorn

Joined: Aug 11, 2008
Posts: 25
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
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 ]
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 38788
    
  23
I have already told you, please Use Code Tags and tell us in the subject line what the topic is about.
Stephen Davies
Ranch Hand

Joined: Jul 23, 2008
Posts: 352
Hi Nitin,

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
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
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


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: 38788
    
  23
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
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
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
Thanks to all members .
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 38788
    
  23
You're welcome.

Please remember about titles for threads in future.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: code problem