• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Protected Class--> Error

 
Rohini Balu
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hi all,

Can anyone tell me why this class throws the following compilation error?

protected class Super
{
private int i=1;

public void show(int i)
{
System.out.println("i is " + i);
}
}
public class Sub extends Super
{

public static void main(String[] args)
{
Super s = new Super();
System.out.println("Hello World!");
s.show(2);
}
}

Error :

>javac Sub.java
Sub.java:11: modifier protected not allowed here
protected class Super
^
1 error
 
Christophe Verré
Sheriff
Posts: 14691
16
Eclipse IDE Ubuntu VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
A top class cannot be protected, neither private.
Only member classes can be.
 
Rahul Bhattacharjee
Ranch Hand
Posts: 2308
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Outer classes can have default or public access specifiers only.
 
Rohini Balu
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks a lot.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic