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 persistence xml in java?

677


What is a bean class?

665


What is cloning in java?

689


Write a program using call by refernce for two different classes to explain to print whether a given number is automorphic or not.

1608


What is lambda expressions action func and predicate?

629


What is difference between map and flatmap in java 8?

647


When a thread is created and started, what is its initial state?

731


What is numberformatexception in java?

653


What is jpa used for?

678


What is reflection in java?

653


What is mdb in java?

692


Please can anybody explain what exactly "the project architecture" means???

1895


What is factory pattern in java?

658


Does netbeans need jdk?

664


how can we create the ui using netbeans,having the code?

1810