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 a stream in java?
What is stateful in java?
How do I install java on windows?
How do you count in java?
explain how java se 8 data and time api solves issues of old java date api?
I have deployed a .war file in my application server comprising of struts and hibernate.If i want to change the "dialect" property of hibernate cfg file how can i change(I have only .war file)... Thanks in advance
What is the meaning of the words public, static and void?
What is jep in java?
How can I swap two variables without using a third variable?
What is injection in java?
Can the main method be overloaded?
What is meant by pass by reference and pass by value in java?
Explain working of java virtual machine (jvm)?
What is a delimiter in java?
Which class is the superclass of every class?