JAVA PROGRAM TO UNDERSTAND ABSTRACT METHODS AND CLASSES

 abstract class Animal {

  abstract void makeSound();


  public void eat() {

    System.out.println("I can eat.");

  }

}


class Dog extends Animal {


  // provide implementation of abstract method

  public void makeSound() {

    System.out.println("Bark bark");

  }

}


public class Main {

  public static void main(String[] args) {


    // create an object of Dog class

    Dog d1 = new Dog();


    d1.makeSound();

    d1.eat();

  }

}

Comments

Popular posts from this blog

PROGRAM FOR BANKERS ALGORITHM FOR DEADLOCK AVOIDENCE

JAVA RECORD PROGRAM FOR AREA AND PERIMETER OF RECTANGLE

JAVA PROGRAM TO PERFORM MULTI THREADING USING RUNNABLE INTERFACE