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 use of entity class in java?
Why is class forname used in java?
What are the authentication modes in asp.net? : java security
In java what is the difference between sleep() and wait() .
What is the difference between swing and awt components?
when i send the request to the JSP page it will print as it is and why? and how to solve this problem please inform me that solution
How common are security breaches? : java security
What is stateless and stateful in java?
What is the front end for java?
How does jpa repository work?
What is stateless object in java?
Is java singleton thread safe?
What is jpa used for?
Why is struts used in java?
What is reflection in java?