0% found this document useful (0 votes)
8 views4 pages

Practica4 1

The document defines classes for figures, squares, and rectangles. It creates figure objects and calculates their areas and perimeters by overriding abstract methods from the base figure class.

Uploaded by

David Castillo
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
8 views4 pages

Practica4 1

The document defines classes for figures, squares, and rectangles. It creates figure objects and calculates their areas and perimeters by overriding abstract methods from the base figure class.

Uploaded by

David Castillo
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 4

Practica 4.

Public class Practica35 {

public static void main(String[] args) {

Figura forma=new Figura();


Cuadrado cubo=new Cuadrado(5);
Rectangulo caja=new Rectangulo(5,3);

Figura []formas= new Figura[3];


formas[0]=forma;
formas[1]=cubo;
formas[2]=caja;

System.out.println(formas[0].area());
System.out.println(formas[1].area());
System.out.println(formas[2].area());

System.out.println(formas[0].perimetro());
System.out.println(formas[1].perimetro());
System.out.println(formas[2].perimetro());
}

}
public class Figura {

public double area(){


return 0;
}
public double perimetro(){
return 0;
}
}
public class Cuadrado extends Figura {
double lado;

public Cuadrado(double lado) {


this.lado = lado;
}

public double area(){


return lado*lado;
}

public double perimetro(){


return lado*4;
}

public double getLado() {


return lado;
}

public void setLado(double lado) {


this.lado = lado;
}

}
public class Rectangulo extends Figura{
double base;
double altura;

public Rectangulo(double base, double altura) {


this.base = base;
this.altura = altura;
}

public double area(){


return base*altura;
}
public double perimetro(){
return base*2+altura*2;
}

public double getBase() {


return base;
}

public void setBase(double base) {


this.base = base;
}

public double getAltura() {


return altura;
}

public void setAltura(double altura) {


this.altura = altura;
}

You might also like