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 difference between adapter class and listener?
Why java uses the concept of the string literal?
Is it possible to define a method in java class but provide it’s implementation in the code of another language like c?
Can we convert integer to string in java?
What methods are used in Servlet?Applet communication?
How do you check if an arraylist is not empty?
How does the java compiler work?
How many types of parsers are there?
Why is String immutable?
What technique can be employed to compare two strings?
Give few difference between constructor and method?
What is collection api?
Why use string handling in Java?
What is Java Package and which package is imported by default?
What is matcher in java?