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
How do you create a jar file?
How do I run a java project?
What is ibatis in java?
What is exe file in java?
What do you understand by casting in java language? What are the types of casting?
Can you compile java into exe?
Are streams faster than for loops?
What is the difference between lambdas and delegates?
What are the advantages of lambda functions?
What is cdi bean in java?
What is explicit casting?
What are messages in java?
What does el mean in java?
What is a service layer in java?
Spring framework ---Can somebody explain me in easily understandable format about AOP, IOC and DI, so that i can explain in interview rather than just telling what is available in net. I am not able to understand that also. I am new to Spring