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 cdi in java?
I want to control database connections in my program and want that only one thread should be able to make database connection at a time. Define how can I implement this logic?
What is type inference? Is type inference available in older versions like java 7 and before 7 or it is available only in java se 8?
Write a program using call by refernce for two different classes to explain to print whether a given number is automorphic or not.
What is http session in java?
What is meant by annotations in java?
How do I enable jvm?
What are jdk tools?
How to reverse the singly linked list(In Node data members are(int data,int pointerTONext))
What are jpa annotations?
What is cache in java?
Where is java installed?
What are the new features about Java se 8 ?
What is cookie in java?
What are microservices in java?