what is default constructor?

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



Post New Answer       View All Answers


Please Help Members By Posting Answers For Below Questions

where are auto variables stored? What are the characteristics of an auto variable?

597


Explain that why C is procedural?

662


What is "Duff's Device"?

705


write a program using linked list in which each node consists of following information. Name[30] Branch Rollno Telephone no i) Write the program to add information of students in linked list

2242


What is the difference between union and structure in c?

581






How to create struct variables?

597


How does sizeof know array size?

634


Write a program to print all permutations of a given string.

647


What is the benefit of using an enum rather than a #define constant?

665


What is .obj file in c?

650


What is the difference between arrays and pointers?

638


Explain a file operation in C with an example.

665


What is the purpose of realloc()?

677


Find the second largest element in an array with minimum no of comparisons and give the minimum no of comparisons needed on an array of size N to do the same.

722


Explain how do you override a defined macro?

592