aspose file tools
The moose likes Beginning Java and the fly likes Please solve the problem... Big Moose Saloon
  Search | Java FAQ | Recent Topics
Register / Login


Win a copy of The Mikado Method this week in the Agile and other Processes forum!
JavaRanch » Java Forums » Java » Beginning Java
Reply Bookmark "Please solve the problem..." Watch "Please solve the problem..." New topic
Author

Please solve the problem...

suresh sai
Ranch Hand

Joined: Jul 16, 2007
Posts: 62
Hi.Iam doing alott to understand the following scenario.Please help me,What is the wrong with the following code.

protected class AnotherClass
{


}


class MyClass
{
public static void main(String l[])
{
System.out.println("hello");

}

}


D:\sureshsai>javac MyClass.java
MyClass.java:1: modifier protected not allowed here
protected class AnotherClass


Thanks and regards
suresh.
marc weber
Sheriff

Joined: Aug 31, 2004
Posts: 11343

Originally posted by chinna suresh:
...MyClass.java:1: modifier protected not allowed here
protected class AnotherClass...

A top-level class cannot be protected or private. If you consider what these modifiers mean, it becomes clear why they can't apply to a top-level class.


"We're kind of on the level of crossword puzzle writers... And no one ever goes to them and gives them an award." ~Joe Strummer
sscce.org
sammaiah kyatham
Ranch Hand

Joined: Aug 03, 2003
Posts: 102
Suresh,
You are using illegal specifier for the class.
Valid modifiers/specifiers are public, abstract and final.

You can use protected access specifier in inner class like below.. which is legal.

public class Test{
protected class MyProtectedTest{

}
private class MyPrivateTest{

}

}

Thanks,
Sam
suresh sai
Ranch Hand

Joined: Jul 16, 2007
Posts: 62
Hi sam,
Thanks for your help and immediate response.I understood from your good example,the modifiers that can be used for a class.But How can I make class that is protected(or private),non-inner(or non-nested) with in the file that contains "main" class or in other separate file?
Thanks in advance.
marc weber
Sheriff

Joined: Aug 31, 2004
Posts: 11343

Originally posted by chinna suresh:
... How can I make class that is protected(or private),non-inner(or non-nested) with in the file that contains "main" class or in other separate file? ...

Again, a top-level (non-nested) class cannot be protected or private.
Kiran Nanjuti
Greenhorn

Joined: Aug 01, 2007
Posts: 4
Hi Suresh
You can only use two access modifiers for classes(public&default) and you can use nonaccess modifiers (abstract,final,strictp).
marc weber
Sheriff

Joined: Aug 31, 2004
Posts: 11343

Originally posted by KiranR:
... You can only use two access modifiers for classes(public&default)...

Note that "default" is not an access modifier. It is one term (of many) to describe the access that results from no access modifier. Other names for this include "friendly," "package," "package friendly," "package default," etc.
 
I agree. Here's the link: http://ej-technologies/jprofiler - if it wasn't for jprofiler, we would need to run our stuff on 16 servers instead of 3.
 
subject: Please solve the problem...
 
Similar Threads
NullPointerException
Annotated Entity Bean Inheritance
please clarify this error...unsupported exception.
inner class????
in what ways can we change this formula..