Tuesday, 23 January 2018

Write a simple java application that creates an interface Shape. The interface declares read() and show() methods and PI as constant data member. Create classes Rectangle and Circle that implement shape interface. Assume suitable data and member methods.




Program:-
interface shape
{
            void read(double x);
            void show();
           
            final static double PI=3.14;
}

class rectangle implements shape
{
            double w=5.0,h;
            public void read(double x)
            {
                        h=x;
            }
            public void show()
            {
                        System.out.println("Area of rectanle is: "+(w*h));
            }
           
}

class circle implements shape
{
            double r;
            public void read(double x)
            {
                        r=x;
            }
             public void show()
            {
                        System.out.println("Area of Triangle is: "+(PI*r*r));
            }
}

class u44
{
            public static void main(String args[])
            {
                        rectangle r = new rectangle();
                        r.read(5.7);
                        r.show();
                       
                        circle c=new circle();
                        c.read(6.0);
                        c.show();
            }
}

No comments:

Post a Comment

It's time To increase blogging capability. To have a chance to contribute in digital world. Any Interested People who want to make t...