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

Write a C program that will accept a hexadecimal number as input and then display a menu that will permit any of the following operations to be carried out: Display the hexadecimal equivalent of the one's complement. (b) Carry out a masking operation and then display the hexadecimal equivalent of the result. (c) Carry out a bit shifting operation and then display the hexadecimal equivalent of the result. (d) Exit. If the masking operation is selected, prompt the user lor the type of operation (bitwise and, bitwise exclusive or, or bitwise or) and then a (hexadecimal) value for the mask. If the bit shifting operation is selected. prompt the user for the type of shift (left or right), and then the number of bits. Test the program with several different (hexadecimal) input values of your own choice.

5105


Explain what is gets() function?

822


What would be an example of a structure analogous to structure c?

782


How is a null pointer different from a dangling pointer?

784


How can I implement sets or arrays of bits?

811


Explain what is operator promotion?

837


How can you draw circles in C?

855


How can I find out if there are characters available for reading?

871


Write a program to check prime number in c programming?

816


What is volatile, register definition in C

897


Differentiate between functions getch() and getche().

809


Explain what does the format %10.2 mean when included in a printf statement?

1124


Explain the difference between call by value and call by reference in c language?

872


In C language, the variables NAME, name, and Name are all the same. TRUE or FALSE?

991


What is assert and when would I use it?

776