wiki:jazz/21-09-22

Version 5 (modified by jazz, 3 years ago) (diff)

--

2021-09-22

  • Object Oriented Programming Concepts
public class HelloWorld{

     public static void main(String []args){
        System.out.println("Hello World");
        
        Animal a = new Cat();
        Animal b = new Kitten();
        
        a.who_am_i();
        b.who_am_i();
     }
}

abstract class Animal {
    abstract void who_am_i();
}

class Cat extends Animal {
    void who_am_i() {
        System.out.println("I'm a Cat");
    }
}

class Kitten extends Cat {
    void who_am_i() {
        System.out.println("I'm a Kitten");
    }
}

Attachments (1)

Download all attachments as: .zip