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 difference between map and flatmap in java?
What is the difference between collection and stream?
What is flatmap in java8?
Are jvm’s platform independent?
Which is faster c++ or java?
What's the difference between local, global and universal groups? : java security
Is php faster than java?
What about javascript? : java security
Write a class which checks whether a given number is prime or not. Write another class to implement the behavior of previous class and print the series of twin prime number upto a given range.
Can optional be null?
What is serializable in java?
What is stateless and stateful in java?
How to reverse the singly linked list(In Node data members are(int data,int pointerTONext))
What is ehcache in java?
What is optional in java 8? What is the use of optional?advantages of java 8 optional?