Write a program in java to demonstrate the This Keyword
public class ThisDemo
{
int w,h,d;
ThisDemo()
{
this(10,10,10);
}
ThisDemo(int w,int h,int d)
{
this.w=w;
this.h=h;
this.d=d;
}
ThisDemo(ThisDemo t3)
{
this(t3.w,t3.h,t3.d);
}
void setvalue(int w,int h,int d)
{
this.w=w;
this.h=h;
this.d=d;
}
void result()
{
System.out.println("Box volume is:"+(w*h*d));
}
public static void main(String[] args)
{
ThisDemo t=new ThisDemo();
t.result();
ThisDemo t1=new ThisDemo(t);
t1.result();
ThisDemo t2=new ThisDemo();
t2.setvalue(10, 20, 30);
t2.result();
}
}
Output
0 comments:
Post a Comment