Ejemplo 1: composición java
public class motherboard{
private CPU cpu;
}
public class CPU{
private int amtOfCores;
private String brand;
}
Ejemplo 2: herencia en java
// Hierarchical inheritance in java
class Animal
{
void eating()
{
System.out.println("animal eating");
}
}
class Lion extends Animal
{
void roar()
{
System.out.println("lion roaring");
}
}
public class Dog extends Animal
{
void bark()
{
System.out.println("dog barking");
}
public static void main(String[] args)
{
Animal obj1 = new Animal();
obj1.eating();
Lion obj2 = new Lion();
obj2.eating();
obj2.roar();
Dog obj3 = new Dog();
obj3.eating();
obj3.bark();
}
}
¡Haz clic para puntuar esta entrada!
(Votos: 0 Promedio: 0)