Page 180 - CTS - CSA TP - Volume 2
P. 180

COMPUTER SOFTWARE APPLICATION - CITS




           4  Output:






















           In this example, Shape  is an abstract class with an abstract method calculateArea().  Concrete  classes
           (Circle and Rectangle) extend Shape and provide their implementations for the calculateArea() method. The
           AbstractClassExample class demonstrates creating instances of concrete classes and calling both abstract and
           concrete methods




           TASK 2: Abstract Class with Multiple Abstract Methods
              // Abstract class
              abstract class Animal {
                  // Abstract methods
                  public abstract void makeSound();
                  public abstract void eat();

                  // Concrete method
                  public void sleep() {
                      System.out.println(“Zzz... (Animal is sleeping)”);
                  }

              }
              // Concrete class 1
              class Dog extends Animal {
                  // Implementing abstract methods
                  @Override

                  public void makeSound() {
                      System.out.println(“Woof! Woof!”);
                  }
                  @Override

                  public void eat() {
                      System.out.println(“Dog is eating”);
                  }
              }





                                                           165
 CITS : IT & ITES - Computer Software Application - Exercise 110  CITS : IT & ITES - Computer Software Application - Exercise 110
   175   176   177   178   179   180   181   182   183   184   185