Latest Tutorials| Questions and Answers|Ask Questions?|Site Map



Home Answers Viewqa Java-Beginners InheritanceTest

Have Programming Question? Ask it here!
 
 
 


remi
InheritanceTest
1 Answer(s)      5 years ago
Posted in : Java Beginners



Advertisement
View Answers

July 28, 2009 at 2:49 PM


Hi Friend,

Try the following code:

class PointEx{
private int x;
private int y;
public PointEx(int i, int j){
x=i;
y=j;
}
}

class Square extends PointEx{
private double sideLength;
public Square(int a,int b,double c){
super(a,b);
sideLength=c;
}
public double area(){
return sideLength*sideLength;
}
public double perimeter(){
return 4*sideLength;
}
}

class Cube extends Square{
private double depth;
public Cube(int x,int y,double z){
super(x,y,z);
depth=z;
}
public double area(){
return 6*super.area();
}
public double volume(){
return super.area()*depth;
}
}

public class InheritanceTest{
public static void main(String args[]){
Square sq=new Square(10,15,25);
System.out.println("Area of Square: "+sq.area());
System.out.println("Circumference of Square: "+sq.perimeter());
System.out.println("**************************");
Cube cu=new Cube(10,15,25);
System.out.println("Area of Cube: "+cu.area());
System.out.println("Volume of Cube: "+cu.volume());
}
}

Thanks


Related Tutorials/Questions & Answers:
InheritanceTest - Java Beginners
()*depth; } } public class InheritanceTest{ public static void main(String
Java Program - Java Beginners
double volume(){ return super.area()*depth; } } public class InheritanceTest
Advertisements
Advertisements
 

 

 

DMCA.com