How to use the Constructor ?
give the some example
Welcome to the Java Programming Forums
The professional, friendly Java community. 21,500 members and growing!
The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.
>> REGISTER NOW TO START POSTING
Members have full access to the forums. Advertisements are removed for registered users.
How to use the Constructor ?
give the some example
What did your research tell you? What is confusing about it?
Suggested reading: Providing Constructors for Your Classes (The Java™ Tutorials > Learning the Java Language > Classes and Objects)
Please write better topic/thread titles. "Java" isn't helpful. "Tell me about constructors" is much better and would alert people that you're asking for basic info that could be easily found in several hundred places on the web and in every Java textbook that's ever been written.
a constructor is called when you use the 'new' keyword.
Is is called when you create a Java object.
e.g.:
public MyClass() { // this is the constructor so you would initialise variable etc within this. // it is called when you instantiate the object } MyClass mc1 = new MyClass(); <----- this will create the object and call the MyClass method (constructor) so anything within the constructor is called at this point.
You really need to learn Object Orientated Programming and the concept of objects etc.
To be fair your question was poorly written so dont expect any great responses.