aspose file tools*
The moose likes Beginning Java and the fly likes Base class private Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Java 8 in Action this week in the Java 8 forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Base class private" Watch "Base class private" New topic
Author

Base class private

Mathew Lee
Ranch Hand

Joined: Jun 08, 2009
Posts: 238
Hi,

I was going through following question from site
http://www.jchq.net/certkey/0102certkey.htm

Question 8)

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[]){
}
}

I have not understood the answer which says


Answer 8)1) Compile time error: Base cannot be private
A top level class such as base cannot be declared to be private.

we are not extending Base class right. Why still it complain.
please advise.
Tags:
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 36578
    
  16
The answer is already given. A top-level class must not be private, because private means visible only inside the class, and that class isn't inside a class to be visible to.
Gaurav Sagar
Ranch Hand

Joined: Sep 08, 2010
Posts: 97

A main class cannot be declared pirvate, only a nested class i.e. a class within a class can be declared as private.

Regards,
Gaurav


SCJP 1.6(91%), SCWCD 1.5(100%), SCBCD in progress
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Base class private
 
Similar Threads
can someone explain?
private
final being overridden??
Mock Test Que...
Marcus Green - Question 8