adspace


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

What if I write static public void instead of public static void?

934


What is the locale class?

1024


What is the first argument of the string array in main method?

1030


what is reflection api? How are they implemented?

1105


How does java handle integer overflows and underflows?

1113


Can we extract main method from another class?

1034


What is the java api?

994


What is the resourcebundle class?

1012


What do you understand by casting in java language? What are the types of casting?

923


Are jvm’s platform independent?

982