Answer Posted / dinesh
All the objects that are created must be given initial
values.There are two approach for this.
1)Using the dot operator to access the instance variables
and then assign values to them individually---This is a
tedious approach.
2)Use of getData method to initialize each object
individually.eg:add.getData(10,15)
To make this simpler Java supports a special type of method
called a Constructor,that enables an object to initialize
itself when it is created.Constructor have the same name as
the class itself and they do not specify a return type,not
even void,bcoz they return the instance of the class itself.
Is This Answer Correct ? | 23 Yes | 4 No |
Post New Answer View All Answers
Why do we create public static method in java?
What does the @override annotation do?
A non-static inner class may have object instances that are associated with instances of the class’s outer class. A static inner class does not have any object instances.
When object is created and destroyed?
What are design patterns and please explain?
What classes of exceptions may be caught by a catch clause in java programming?
Why is singleton class used?
State one difference between a template class and class template.
What is the difference between equals() and == in java?
What is contract between hashcode and equal method?
What is bubble sorting in java?
What are abstract methods in java?
Can we overload the constructors?
Can we force garbage collector to run ?
What are the practical benefits, if any, of importing a specific class rather than an entire package (e.g. Import java.net.* Versus import java.net.socket)?