what is constructer?what are the type of constructer with
example.
Answer Posted / prasad
A constructor is a method.it used to custom intialization
for an object.constructor name and class name is same.
consructor should not return any value not even void also.
A constructor will Executed at the time of initialization of
an object.
Different types of constructors:
--------------------------------
1)default constructor
2)parametarized constructor
Ex:
class sum{
int a,b;//instance variables
sum(int a,int b){
System.out.printl("sum of two numbers="+(a+b));
}
}
class Example{
psvm(String s[])throws Exception{
sum s=new sum(10,10);
}
}
o/p:sum of two numbers=20
/*here the constructor will be executed at the time of
creating the object*/
Is This Answer Correct ? | 0 Yes | 2 No |
Post New Answer View All Answers
What is the content reside in Use case Document?
What is an api in java?
What is the java api?
What is the difference between jar and executable jar?
What is a cookie in java?
What is property file in java?
Do I need to install jre if I have jdk?
What is dao in java?
What is jdk for netbeans ide?
What is lazy loading in jpa?
What is mdb in java?
How do I start netbeans?
What is stateless and stateful in java?
What if the main method is declared as private?
What is @override annotation in java?