Java Program showing use of abstract keyword…

This java program shows an example of abstract class.
abstract class Math1
{
                double no;
                abstract double calculate();
}
class Square extends Math1
{
                double calculate()
                {
                                return (no*no);
                }
}
class Cube extends Math1
{
                double calculate()
                {
                                return (no*no*no);
                }
}
class AbstractDemo
{
                public static void main(String args [])
                {
                                Square s=new Square();
                                s.no=2.5;
                                System.out.println(“Square of number : ” + s.calculate());
               
                                Cube c=new Cube();
                                c.no=2.5;
                                System.out.println(“Cube of number : ” + c.calculate());
                }

}

Add Comment