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

c programming of binary addition of two binary numbers

4 Answers  


When can a far pointer be used?

0 Answers  


what is the output of the following program? #include<stdio.h> void main() { int x=4,y=3,z; z=x-- -y; printf("\n%d %d %d",x,y,z); }

14 Answers  


Can you please explain the difference between malloc() and calloc() function?

0 Answers  


What is spark map function?

0 Answers  






What is void main () in c?

0 Answers  


Write a code of a general series where the next element is the sum of last k terms.

0 Answers   Aspiring Minds,


How can you allocate arrays or structures bigger than 64K?

0 Answers  


Describe the header file and its usage in c programming?

0 Answers  


What is strcpy() function?

0 Answers  


What is the difference between specifying a constant variable like with constant keyword and #define it? i.e what is the difference between CONSTANT FLOAT A=1.25 and #define A 1.25

0 Answers  


Explain in detail how strset (string handling function works )pls explain it with an example.

1 Answers  


Categories