File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
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
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.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Protected Class--> Error
 
Similar Threads
Possible error in K&B book (resolved - no error)
How to set classpath
Package Accessibility
Inheritance Issue