This week's book giveaway is in the Servlets forum.
We're giving away four copies of Murach's Java Servlets and JSP and have Joel Murach on-line!
See this thread for details.
The moose likes Java in General and the fly likes Protected method in a packaged superclass not being called by subclass Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Java » Java in General
Reply locked New topic
Author

Protected method in a packaged superclass not being called by subclass

kunal Agarwal
Greenhorn

Joined: Aug 15, 2011
Posts: 15
Hi,
This is my first post to this forum. I have started preparing for SCJP recently and I am totaly confused with the following code.
Can't find an answer by myself.

Fruit.java is in a package foo.

package foo;
public class Fruit
{
protected void k()
{
}
}



And implementing class Apple is having default access.

import foo.Fruit;
class Apple extends Fruit
{
public static void main(String a[])
{
Fruit b = new Apple();///Code fails to compile...If the new Apple object is assigned to a Apple b object then it runs fine...
b.k();
}
}



What am I missing here? Thanks...
kunal Agarwal
Greenhorn

Joined: Aug 15, 2011
Posts: 15
I think this is not the correct place to ask this question.
I have posted it in the Beginning Java forum. Thanks...
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
 
subject: Protected method in a packaged superclass not being called by subclass
 
Similar Threads
Constructor of parent abstrat class not getting executed.
Question about packages
Access Modifier protected -- SCJP Study Guide page 36
Protected method in a packaged superclass not being called by subclass
Polymorphic calls