+ 1
I want an example that shows me inheritance in Java because Im confused ...!
3 Antworten
+ 3
abstract class Animal {
abstract void talk();
}
class Dog extends Animal {
public void talk() {
System.out.println("woof!");
}
}
class Cat extends Animal {
public void talk() {
System.out.println("meow!");
}
}
class MyClass {
public static void main(String[ ] args) {
Dog dog = new Dog();
Cat cat = new Cat();
dog.talk();
cat.talk();
}
}
>>>
woof!
meow!
+ 1
Thanks ♥
0
lvl 1 crook
this is awesome thanks 😊