Skip to Main Content

New to Java

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

How access Instance Variable of super class in sub class Method()

807600Sep 4 2007 — edited Sep 5 2007
i am using two classes in which the super class consists of instance variable and i want that instance variable to be access in the subclass method.....

example:

class Figure
{
double length;
double breadth;
}

class Rectangle extends Figure
{
Rectangle()
{
super();
}
double area() // i want to acess this method.......
{
return(length * breadth);
}
}

class FigureDemo
{
public static void main(String[] args)
{
Figure f = new Rectangle();
f.length = 10.0;
f.breadth = 10.0;
f.area();
System.out.println("Area of Rectanle is"+ f.area());
}
}


Note: I want to excute the same code return in the Main method.
How to can i access super class instance variable in sub class method.. please help out on this........


Thanks & regards,

Ravi
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Oct 3 2007
Added on Sep 4 2007
5 comments
815 views