what is default constructor?

Answers were Sorted based on User's Feedback



what is default constructor?..

Answer / venugopal

In d object_oriented programs actually we interacting with
the methods with the objects only.Objects are constructed
when we create an object the compiler automatically calls
one constructor i.e default constructor.if we explicitily
mention a constructor i.e if we pass any arguments it is
called explicit constructor.
This can be briefly explained based on below ex. i am
writing d code in java.
class Sample
{
int x,y;
Sample()
{
x=12;
y=13;
}
Sample(int a,int b)
{
x=a;
y=b;
}
void display()
{
System.out.println("values are"+x+y);
}
}
class SampleDemo
{
public static void main(String args[])
{
Sample s=new Sample();//default constructor;
s.display();
Sample s1=new Sample(12,13);//parameterized constructor
s1.display();
}
} if u have any doubts contact me
venugopal.palavalasa@gmail.com

Is This Answer Correct ?    1 Yes 0 No

what is default constructor?..

Answer / vaibhav

in java once the memory is instantiated at that time constructor will call by internally.

Is This Answer Correct ?    0 Yes 0 No

Post New Answer

More C Interview Questions

void main() { static int i = 5; if(--i) { main(); printf("%d ",i); } } what would be output of the above program and justify your answer? }

5 Answers   C DAC, CDAC, Infosys, Wipro,


How to reverse a string using a recursive function, without swapping or using an extra memory?

31 Answers   Cisco, Mind Tree, Motorola, Ophio, Sony, TCS, Wipro,


how logic is used

0 Answers  


how can i sort numbers from ascending order and descending order using turbo c..

1 Answers  


Is main a keyword in c?

0 Answers  






When should the volatile modifier be used?

0 Answers  


What is a class c rental property?

0 Answers  


How is actual parameter different from the formal parameter?

0 Answers  


What does calloc stand for?

0 Answers  


What does %2f mean in c?

0 Answers  


how to print this pyramid * * * * * * * * * * * * *

2 Answers  


Why c++ is called c++ and not c+?

9 Answers   EBS,


Categories