Demonstration of constructor overloading.
Java Program :
class const_overload
{
int a,b,c;
const_overload()
{
a=12;
b=60;
c=a+b;
}
const_overload(int p,int q)
{
a=p;
b=q;
c=a+b;
}
void display()
{
System.out.print("Value : "+c);
}
}
Java Program :
class const_overload
{
int a,b,c;
const_overload()
{
a=12;
b=60;
c=a+b;
}
const_overload(int p,int q)
{
a=p;
b=q;
c=a+b;
}
void display()
{
System.out.print("Value : "+c);
}
}
Good article.I have also shared my view as Why Constructor overloading is needed in Java
ReplyDeleteIT IS ONE OF THE PRINCIPLE OF OOP.
DeleteConstructor overloading enables to create an object of class and constructor is used to initialise data members to perform other complex tasks..
Delete~hope dis will help u
Pls make program for...
ReplyDeleteClass name-result
Member function - name,rollno, sub1&sub2
Constructor to initialize
result(String, int)
Input(int,int,int)
Double()
Char grade(double)
And display() method
some more examplese
ReplyDelete