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
What is the use of flatmap in java 8?
How do I install eclipse?
What is phantom memory?
What is stateless class in java?
What is resultsetmetadata in java?
Can a method be static and synchronized?
Please can anybody explain what exactly "the project architecture" means???
Which framework is best for rest api java?
What does el mean in java?
What do I need to install netbeans?
Is php faster than java?
What is the most important feature of java?
What is the meaning of loosely coupled in java?
What is orm in java?
How do I install jdk?