public class Inheritance {
|
|
public static int main() {
|
|
Dog dog = new Dog();
|
|
dog.age = 5;
|
|
|
|
dog.speak();
|
|
dog.showAge();
|
|
|
|
return 0;
|
|
}
|
|
}
|
|
|
|
class Animal {
|
|
int age;
|
|
|
|
void speak() {
|
|
System.out.println("Animal speaks");
|
|
}
|
|
|
|
void showAge() {
|
|
System.out.println(this.age);
|
|
}
|
|
}
|
|
|
|
class Dog extends Animal {
|
|
void speak() {
|
|
System.out.println("Woof!");
|
|
}
|
|
}
|