This week's giveaway is in the EJB and other Java EE Technologies forum.
We're giving away four copies of EJB 3 in Action and have Debu Panda, Reza Rahman, Ryan Cuprak, and Michael Remijan on-line!
See this thread for details.
The moose likes Beginning Java and the fly likes protected access modifier using inheritance Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of EJB 3 in Action this week in the EJB and other Java EE Technologies forum!
JavaRanch » Java Forums » Java » Beginning Java
Reply locked New topic
Author

protected access modifier using inheritance

Lisa Dissousa
Greenhorn

Joined: Sep 18, 2012
Posts: 3
package p1;
public class A
{
protected int a = 10;
public static void main(String[] args)
{
System.out.println("Hello World!");
}
}


package p2;
import p1.A;
public class B extends A
{

public static void main(String[] args)
{
A a1 = new A();
System.out.println(a1.a);
}
}

I am getting a compilation error: 'a' has protected access in A. But protected means it can be accessible in sub class which is in different package also right
R. Jain
Ranch Hand

Joined: Aug 11, 2012
Posts: 367
    
    1

It's strange>>> How come, two exactly same topic with same heading and same question can be started by two different Users...

Anyways.. Lisa, you can refer to this post where
I have given the answer for this same question..
Jesper de Jong
Java Cowboy
Saloon Keeper

Joined: Aug 16, 2005
Posts: 13868
    
  10

Locking this one, since it's exactly the same as the other post, even though it's by another user. (Do you have two accounts??).

Java Beginners FAQ - JavaRanch SCJP FAQ - The Java Tutorial - Java SE 7 API documentation
Scala Notes - My blog about Scala
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: protected access modifier using inheritance
 
Similar Threads
Please explain this code
Q of inner class in different package
protected method not being overridden in diff. package
Method parameter
protected access modifier using inheritance