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
Tell us something about different types of casting?
Can the garbage collection be forced by any means?
What class allows you to read objects directly from a stream in java programming?
What is string array?
How list contains works in java?
Difference between serialization and deserialization in java?
What does percent mean in java?
Can we make constructors static?
Why packages are used?
What is the difference between && and & in java?
How will you add panel to a frame?
Explain scope or life time of local variables in java?
Is null or empty java?
What is the use of java?
What is Java Annotations?