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

What does the c in ctime mean?

815


Is c# a good language?

808


How do I use void main?

864


how to find anagram without using string functions using only loops in c programming

2962


What is the meaning of && in c?

775


What is the difference between text and binary modes?

899


How can I make it pause before closing the program output window?

824


What is the code for 3 questions and answer check in VisualBasic.Net?

1929


what is the height of tree if leaf node is at level 3. please explain

1864


WHAT IS THE DEFINATION OF IN TECHNOLOGY AND OFF TECHNOLOGY ?

2125


What is the use of a conditional inclusion statement in C?

857


Where are some collections of useful code fragments and examples?

969


In c language can we compile a program without main() function?

867


Write a C program on Centralized OLTP, Decentralized OLTP using locking mechanism, Semaphore using locking mechanism, Shared memory, message queues, channel of communication, sockets and a simple program on Saving bank application program using OLTP in IPC?

2451


code for quick sort?

1833