-
inheritance question
i have a class Bag that has local variables . . . .
private int i=10;
private int [] x;
private int top_pos=0;
class Bag has a get method for an array value, a set method for an array value, a toString override, etc.
i want to make a class BagExt that EXTENDS the Bag class. BagExt will inherit all of Bag's methods, but will override one and maybe overload one (just trying to get familiar with how inheritance works).
so i tried to do the following . . .
public class BagExt extends Bag{
public BagExt (){
super();
}
public void add (int val){
i += val;
}
public int show_i (){
return i;
}
but when i try to compile, i get an error that "i" has private access in Bag. so do i have to declare similar variables of my own? and how is it that the default constructor will work? . . . it uses the Bag private varialbe of "int [] x".
how do i get this to work?
thanks
crq
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
Forum Rules
|
Top DevX Stories
Easy Web Services with SQL Server 2005 HTTP Endpoints
JavaOne 2005: Java Platform Roadmap Focuses on Ease of Development, Sun Focuses on the "Free" in F.O.S.S.
Wed Yourself to UML with the Power of Associations
Microsoft to Add AJAX Capabilities to ASP.NET
IBM's Cloudscape Versus MySQL
|
Bookmarks