Results 1 to 4 of 4
  1. #1
    MithunDhar is offline Member
    Join Date
    Mar 2009
    Posts
    7
    Rep Power
    0

    Default [SOLVED] Method Overriding

    The below-mentioned program might run well in your pc. But its showing an error in my program. Can anyone say me the reason for this error?

    Error is :
    C:\java\bin>javac overriding.java
    overriding.java:27: missing return statement
    }
    ^
    1 error
    C:\java\bin>


    //program name : overriding
    class figure
    {
    double sidea,sideb;
    figure(double a,double b)
    {
    sidea=a; sideb=b;
    }
    figure(double a)
    {
    sidea=a; sideb=a;
    }
    double area()
    {
    System.out.println("Area inside class is undefined");
    return 0;
    }
    }
    class rectangle extends figure
    {
    rectangle(double a,double b)
    {
    super(a,b);
    }
    double area()
    {
    System.out.println("Area of rectangle is "+(sidea*sideb));
    }
    }
    class square extends figure
    {
    square(double a)
    {
    super(a);
    }
    double area()
    {
    System.out.println("Area of square is "+(sidea*sideb));
    }
    }


    class overriding
    {
    public static void main(String args[])
    {
    figure f=new figure(34,20);
    System.out.println("Welcome of Overriding Demo");
    f.area();
    rectangle r=new rectangle(20,40);
    r.area();
    square s=new square(21);
    s.area();
    }
    }

  2. #2
    emceenugget is offline Senior Member
    Join Date
    Sep 2008
    Posts
    564
    Rep Power
    7

    Default

    whatever method contains line 27 is missing a required return statement.

  3. #3
    vijayabaskar is offline Member
    Join Date
    Apr 2009
    Posts
    37
    Rep Power
    0

    Default

    Hi..
    you can try like this..

    class figure
    {
    double sidea,sideb;
    figure(double a,double b)
    {
    sidea=a; sideb=b;
    }
    figure(double a)
    {
    sidea=a; sideb=a;
    }
    double area()
    {
    System.out.println("Area inside class is undefined");
    return 0;
    }
    }
    class rectangle extends figure
    {
    rectangle(double a,double b)
    {
    super(a,b);
    }
    double area()
    {
    return(sidea*sideb);

    }
    }
    class square extends figure
    {
    square(double a)
    {
    super(a);
    }
    double area()
    {
    return(sidea*sideb);

    }
    }


    class overriding
    {
    public static void main(String args[])
    {
    figure f=new figure(34,20);
    System.out.println("Welcome of Overriding Demo");
    System.out.println("f.area"+f.area());
    rectangle r=new rectangle(20,40);
    System.out.println("r.area"+r.area());
    square s=new square(21);
    System.out.println("s.area"+s.area());
    }
    }


    u have to return the double value.. but u not..

  4. #4
    MithunDhar is offline Member
    Join Date
    Mar 2009
    Posts
    7
    Rep Power
    0

Similar Threads

  1. Replies: 1
    Last Post: 04-01-2009, 03:00 AM
  2. Replies: 7
    Last Post: 02-26-2009, 07:46 AM
  3. Replies: 1
    Last Post: 02-10-2009, 11:03 AM
  4. Replies: 3
    Last Post: 04-08-2008, 08:12 AM
  5. is overriding static method possible
    By raghu in forum Advanced Java
    Replies: 1
    Last Post: 01-22-2008, 01:38 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •