aspose file tools*
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes private and protected  modifier  in top level class Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "private and protected  modifier  in top level class" Watch "private and protected  modifier  in top level class" New topic
Author

private and protected modifier in top level class

nishesh chouhan
Ranch Hand

Joined: Nov 06, 2000
Posts: 37
Q) see the following code
public class A
{
public stratic void main(String str[])
{
}
}
class B extends A // (1)
{
// some code
}
if at (1) I put private the compiler says that package members should
be accessible to the package members
and if I put protected then it says that class or interface declaration
expected
but I think that they should be allowed as they are applied to class which does not contain main method what is the problem with that
anyone ps explain me that ..
Sean Casey
Ranch Hand

Joined: Dec 16, 2000
Posts: 625
A top level class may not be protected or private. An inner class can be though.
Athiveera Kugan
Greenhorn

Joined: Mar 21, 2001
Posts: 15
hai,
The class which you are declaring as private is package level class, that can declared as public or default


<I> s.a.kugan</I>
Athiveera Kugan
Greenhorn

Joined: Mar 21, 2001
Posts: 15
hai,
The class which you are declaring as private is package level class, that can declared as only public or default .
Athiveera Kugan
Greenhorn

Joined: Mar 21, 2001
Posts: 15
hai,
The class which you are declaring as private is package level class, that can be declared as only public or default .
<marquee>by s.a.kugan</marquee>
Athiveera Kugan
Greenhorn

Joined: Mar 21, 2001
Posts: 15
hai,
The class which you are declaring as private is package level class, that can be declared as only public or default .
<marquee>by s.a.kugan</marquee>
koray guclu
Ranch Hand

Joined: Feb 23, 2001
Posts: 59
hi
It is not related with main method. main() is just a method compiler only complain when you want to run the class and tells there isnot any main() method described.
A top level class can not have private or protocted modifiers! This is the rule.
class A ....
{
public static void main...
}
class B extends A {
}
main method is inherited to class B you can run class B too.

-----------------------------------------------------<BR> Koray GUCLU ~ the sky has no limit ~<BR> (B.s. Computer Engineer)<BR> Frankfurt am Main, Germany<BR> web : <A HREF="http://www.geocities.com/korayguclu/<BR rel="nofollow">" TARGET=_blank>http://www.geocities.com/korayguclu/<BR></A> mail: korayguclu@yahoo.com<BR>-----------------------------------------------------
kriti sharma
Ranch Hand

Joined: Feb 16, 2001
Posts: 160
hello nishesh,
u r a ranch hand. this means u have cleared SCJP.but u put up very basic questions on the board.
i can't digest this.would u mind if i ask ur score on the test.
kriti
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: private and protected modifier in top level class
 
Similar Threads
Protected
conflict: inheritance, package and import access
Confused with protected access
Protected members
Private variables aren't inherited?