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


Please Help Members By Posting Answers For Below Questions

How do you create a jar file?

696


How do I run a java project?

656


What is ibatis in java?

675


What is exe file in java?

680


What do you understand by casting in java language? What are the types of casting?

621


Can you compile java into exe?

747


Are streams faster than for loops?

654


What is the difference between lambdas and delegates?

656


What are the advantages of lambda functions?

701


What is cdi bean in java?

691


What is explicit casting?

723


What are messages in java?

646


What does el mean in java?

782


What is a service layer in java?

607


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

1757