File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
    Bookmark Topic Watch Topic
  • New Topic

protected access modifier using inheritance

 
Lisa Dissousa
Greenhorn
Posts: 3
  • 0
  • Mark post as helpful
  • send pies
  • Report post to moderator
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
Posts: 375
1
Java Python Ubuntu
  • 0
  • Mark post as helpful
  • send pies
  • Report post to moderator
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
Pie
Posts: 15150
31
Android IntelliJ IDE Java Scala Spring
  • 0
  • Mark post as helpful
  • send pies
  • Report post to moderator
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??).
 
I agree. Here's the link: http://aspose.com/file-tools
    Bookmark Topic Watch Topic
  • New Topic