what are the types of constructer explain with example

Answer Posted / srinu

There are Two types of constructors
1)Parameterized constructor in which give the parameter
EX:-
class A1
{

A1(int a)
{
System.out.println("HAI HOW ARE U");
}
}
public class A
{
public static void main(String k[])
{
A1 a1=new A1(5);
}
}
2)Default Constructor :- There are no argument in the
constructor is called Default Constructor
class A1
{

A1()
{
System.out.println("HAI ");
}
}
public class A
{
public static void main(String k[])
{
A1 a1=new A1();
}
}

Note: In our java class their is constructor JVM will create
one default constructor.If our class contain default
constructor or parameter constructor or both then that
time JVM will not create Default constructor

Is This Answer Correct ?    5 Yes 2 No



Post New Answer       View All Answers


Please Help Members By Posting Answers For Below Questions

What is the difference between ec2 and lambda?

480


Which is more secure: java or activex? : java security

515


What is transactional in java?

523


What is phantom memory?

548


What is jsr in java?

488






What is the use of lambda functions?

495


How many types of jdk are there?

490


What are anonymous methods and lambda expression?

435


What is java web application?

470


Why java?

538


What about products that claim to block java applets at a firewall? : java security

493


Why is struts used in java?

487


What is java aop?

475


In java what is the difference between sleep() and wait() .

514


Is lambda expression an object?

491