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 Beginning Java and the fly likes Protected Class--> Error 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 » Beginning Java
Bookmark "Protected Class--> Error" Watch "Protected Class--> Error" New topic
Author

Protected Class--> Error

Rohini Balu
Greenhorn

Joined: Sep 20, 2006
Posts: 2
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

Joined: Nov 24, 2005
Posts: 14687
    
  16

A top class cannot be protected, neither private.
Only member classes can be.


[My Blog]
All roads lead to JavaRanch
Rahul Bhattacharjee
Ranch Hand

Joined: Nov 29, 2005
Posts: 2308
Outer classes can have default or public access specifiers only.


Rahul Bhattacharjee
LinkedIn - Blog
Rohini Balu
Greenhorn

Joined: Sep 20, 2006
Posts: 2
Thanks a lot.
 
wood burning stoves
 
subject: Protected Class--> Error
 
Similar Threads
Inheritance Issue
How to set classpath
Package Accessibility
Possible error in K&B book (resolved - no error)