wiki:jazz/21-09-22

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");
    }
}
using System.IO;
using System;

class Program
{
    static void Main()
    {
        Console.WriteLine("Hello, World!");
        Animal animal = new Cat();
        animal.who_am_i();
        animal = new Kitten();
        animal.who_am_i();
    }
}

abstract class Animal
{
    public abstract void who_am_i();
}

class Cat:Animal
{
    public override void who_am_i() {
        Console.WriteLine("I'm a Cat");
    }
}

class Kitten:Cat
{
    public override void who_am_i() {
        Console.WriteLine("I'm a Kitten");
    }
}
Last modified 3 years ago Last modified on Oct 10, 2021, 10:38:25 AM

Attachments (1)

Download all attachments as: .zip