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
Can we call a non-static method from inside a static method?
Can we override data members in java?
What are the approaches that you will follow for making a program very efficient?
What is use of set in java?
What is a treeset class?
What is meant by interface?
What is object-oriented programming?
Why do we use bufferedreader?
What is difference between word and integer?
Explain wrapper classes in java?
What is the difference between access specifiers and access modifiers in java? 16
What is oops in java?
What best practices should you follow while writing multithreaded code in java?
What is thread life cycle in java?
What is the difference between Array and Hash Table?