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

How do I run a java project in netbeans?

557


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

1760


What are jpa annotations?

554


What java systems libraries and methods are available for me to use?

535


What is the locale class?

617






Can java program run without jdk?

592


What is a java singleton?

550


What does @override mean in java?

556


Does netbeans need jdk?

559


What is a container in java?

540


1.can i use super keyword in normal class(not inheritance) to call any method?if so how can i call particular variable? 2.In the inheritance how can i access the particular variable from the base class(it containing 5 variables) using super keyword?

1730


Which class is the superclass of every class?

596


What is the difference between collection and stream?

551


What is the use of jprofiler?

559


What is java lang exceptionininitializererror?

561