Create an abstract class named shape, that contains an empty method named numberOfSides(). Define three classes named Trapezoid, Triangle and Hexagon, such that each one of the classes contains only the method numberOfSides(), that contains the number of sides in the given geometrical figure.

 /* Abstract classes 25-11-2022 */

abstract class Shape

{

     abstract void noofsides();

}


class Trapezoid extends Shape

{

     void noofsides()

     {

    System.out.println("Trapezoid had 4 sides");

     }

}


class Triangle extends Shape

{

     void noofsides()

     {

    System.out.println("Triangle had 3 sides");

     }

}


class Hexagon extends Shape

{

     void noofsides()

     {

    System.out.println("Hexagon had 6 sides");

     }

}


class Abstract_Noofsides_4A

{

  public static void main(String args[])

  {

Trapezoid tr = new Trapezoid();

tr.noofsides();

Triangle t = new Triangle();

t.noofsides();

Hexagon h = new Hexagon();

h.noofsides();

  }

}

Comments

Popular posts from this blog

Design GUI to handle Choice Control event.

Write a Java program that reads an integer number (between 1 and 255) from the user and prints the binary representation of the number. The answer should be printed as a String. Note: The output displayed should contain 8 digits and should be padded with leading 0s(zeros), in case the returned String contains less than 8 characters. For example, if the user enters the value 16, then the output should be 00010000 and if the user enters the value 100, the output should be 01100100 (Hint : You may use String.format() method for the expected output)