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
Why there are no global variables in java?
What is repository pattern in java?
What are the risks in java security? : java security
What is a controller in java?
program A and B are analysed and found to have worst case running time greater than 150NlogN and N*N respectively. which program has the better guarantee after the running time for the large values of N(N>10000)? which program has the better guarantee for the running time of small program N (N<100)? which program will run faster on average for N=1000?
What is java aop?
Is php faster than java?
What is a driver in java?
How do you run an executable jar file?
What if I do not provide the string array as the argument to the method?
What is meant by annotation in java?
What are the authentication modes in asp.net? : java security
What is setstring method in java?
What is property file in java?
What's the difference between local, global and universal groups? : java security