A Lecture Number Oop3 (Java)
A Lecture Number Oop3 (Java)
1. class Animal{
2. void eat(){
3. System.out.println("eating...");
4. }
5. }
6. class Dog extends Animal{
7. void bark(){System.out.println("barking...");}
8. }
9. class Cat extends Animal{
10. void meow(){System.out.println("meowin
g...");}
11. }
12. class TestInheritance3{
13. public static void main(String args[]){
14. Cat c=new Cat();
15. c.meow();
16. c.eat();
17. //c.bark();//C.T.Error
18. }}
Output:
meowing...
eating...