what are the types of constructer explain with example

Answers were Sorted based on User's Feedback



what are the types of constructer explain with example..

Answer / kailash

there are two types of Constructors .
1. Parameterized Constructor inwhich we give arguments .
2. Default constructor , there no argument is given .
for each class there must be a defult constructor .

Is This Answer Correct ?    14 Yes 2 No

what are the types of constructer explain with example..

Answer / siri

there are three kinds parametrized,default and copy consturctor

Is This Answer Correct ?    7 Yes 0 No

what are the types of constructer explain with example..

Answer / 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

More Java Related AllOther Interview Questions

What is javax annotation generated?

0 Answers  


Which method is used to create the daemon thread?

0 Answers  


Can a method be static and synchronized?

0 Answers  


public class Dog { private int weight; public int getweight(){ return weight; } public void SetWeight(int newWeight){ if (newWeight > 0){ weight = newWeight; } } } public class TestDog { public static void main(String[] args) { Dog d = new Dog(); System.out.println("Dog d's weight is " + d.getWeight()); d.setWeight(42); System.out.println("Dog d's weight is " + d.getWeight()); d.setweight(-42); System.out.println("Dog d's weight is " + d.getWeight()); } } class dog is compiled but there is an error in class TestDog when compiled and the error is with dot notations. I want to kmow why there is error in testdog class when compiled.

3 Answers  


Is java an api?

0 Answers  






How do you find lambda?

0 Answers  


What is java lang?

0 Answers  


What is meant by java se?

0 Answers  


Why is struts used in java?

0 Answers  


In which language eclipse is developed?

0 Answers  


What is the java api?

0 Answers  


How do I enable java in firefox?

0 Answers  


Categories