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
What is a bufferedreader?
What is an arraylist in java?
What is numeric data type?
explain different ways of using thread? : Java thread
How is java hashmap implemented?
What is a byte string?
Is space a character in java?
What is the Scope of Static Variable?
What do you mean by static variable?
How do you start a thread?
Describe different states of a thread.
Is multiple inheritance supported by java?
What is an object in java and how is it created?
How to handle a web browser resize operation?
Mention a package that is used for linked list class in java.