aspose file tools*
The moose likes Beginning Java and the fly likes Inner Classes Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of The Java EE 7 Tutorial Volume 1 or Volume 2 this week in the Java EE forum
or jQuery UI in Action in the JavaScript forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Inner Classes" Watch "Inner Classes" New topic
Author

Inner Classes

V Bose
Ranch Hand

Joined: Jul 10, 2003
Posts: 113
1. If B extends A and
2. C is a public inner class of B
Does it imply that A is an enclosing class of C ?
Michael Morris
Ranch Hand

Joined: Jan 30, 2002
Posts: 3451
Originally posted by V Bose:
1. If B extends A and
2. C is a public inner class of B
Does it imply that A is an enclosing class of C ?

Nope. B is the enclosing class only. Inner classes have access to all state including private state of its inclosing class, C would not have access to A's state.


Any intelligent fool can make things bigger, more complex, and more violent. It takes a touch of genius - and a lot of courage - to move in the opposite direction. - Ernst F. Schumacher
V Bose
Ranch Hand

Joined: Jul 10, 2003
Posts: 113
Is it safe to state :
If a subclass 'inherits' a member, the subclass 'has' the member.
for Ex.
public class SportsCar
{
float calcSpeed{}
void goFast(){}
void doStuff()
{
goFast();
}
}
public class Convetible extends SportsCar
{
void lowerTop(){};
void doMore()
{
goFast(); //in Super class...
//after inheritance Convertible
//'has' member goFast()
lowerTop();
}
}
Is it legal to have a Convertible like this then..
public class Convetible extends SportsCar
{
float s1;
void lowerTop(){};
doMore()
{
goFast(); //in Super class...
s=calcSpeed();//in Super class..
lowerTop();
}
public class getWindSpeed //Inner Class
{
float s2;
s2=calcSpeed();//Can't I see calcSpeed() since
//my enclosing class inherited
//('has') the method calcSpeed
}
}
Sorry if I am repeating the question. I'm trying to see if I am understanding the concept properly...
Michael Morris
Ranch Hand

Joined: Jan 30, 2002
Posts: 3451
You had some sytax errors in the code, so I will repost it here:

SportsCar.java

Convetible.java

Yep you can do that. One thing you must note here is the fact that all of your methods have default or package-private access. If the inheriting classes were in a different package then none of the methods in SprotsCar would be accessible from the child class.
 
 
subject: Inner Classes