class Demo{
double base;
double height;
Demo(){
System.out.println("Constructor with no parameter");
}
Demo(Demo dm){
base = dm.base;
height = dm.height;
}
Demo(double height, double base){
this.height = height;
this.base = base;
}
Demo(double len){
this.height = len;
this.base = len;
}
double area(){
return 0.5*base*height;
}
}
public class Main{
public static void main(String args[]){
Demo dm = new Demo(10.0, 5.0);
Demo dm2 = new Demo(5.0,3.0);
Demo dm3 = new Demo(dm);
System.out.println(dm.area());
System.out.println(dm2.area());
System.out.println(dm3.area());
}
}
Using Object as a parameter
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment