aspose file tools*
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes private 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" Watch "private" New topic
Author

private

Anonymous
Ranch Hand

Joined: Nov 22, 2008
Posts: 18944
Hi!, I found in a MOK exam:
What will happen when you attempt to compile and run this code?
private class Base{}
public class Vis{
transient int iVal;
public static void main(String elephant[]){}}
1) Compile time error: Base cannot be private
2) Compile time error indicating that an integer cannot be transient
3) Compile time error transient not a data type
4) Compile time error malformed main method
The correct answer is the number one, but why???
thanks.
Jason Li
Ranch Hand

Joined: Jun 24, 2001
Posts: 46
top level class can only be public or default.
See JLS 8.1.1 http://java.sun.com/docs/books/jls/second_edition/html/classes.doc.html#21613
Jason


green horn
Anonymous
Ranch Hand

Joined: Nov 22, 2008
Posts: 18944

Thank you Jason Li.
Tamanna Mittal
Greenhorn

Joined: Jun 03, 2001
Posts: 21
But in this case the other class is not being derived from the base class so Y giving error.
------------------
Cheers
Tamanna :-)


Cheers<BR>Tamanna :-)
Anonymous
Ranch Hand

Joined: Nov 22, 2008
Posts: 18944

Thanks for all
kavita desai
Greenhorn

Joined: Jul 09, 2001
Posts: 16
Hi Tamanna,
it does not matter if class Vis extends Base or not. any class that is not inside another class is called a top level class and a top level class cannot be private or protected. it can only be either public or default.
all the best
Kavita.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: private