Win a copy of Mesos in Action this week in the Cloud/Virtualizaton forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Inner Classes

 
V Bose
Ranch Hand
Posts: 113
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 3451
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
V Bose
Ranch Hand
Posts: 113
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 3451
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic