Sunday, 4 August 2013

Constructor using Java

callpcons.java

class pcons
{
int a,b;
pcons(){};
pcons(int a,int b){
this.a=a;
this.b=b;
}
void display(){
System.out.println("A="+a);
System.out.println("B="+b);
}
}
class callpcons
{
public static void main(String args[]){
pcons xx=new pcons();
pcons ob=new pcons(20,20);
pcons obj=new pcons(30,40);
xx.display();
ob.display();
obj.display();
}
}

Output:
A=0
B=0
A=20
B=20
A=30
B=40


Thanks for watching... comment it.

No comments:

Post a Comment