File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
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
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Base class private" Watch "Base class private" New topic

Base class private

Mathew Lee
Ranch Hand

Joined: Jun 08, 2009
Posts: 238

I was going through following question from site

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.
Campbell Ritchie

Joined: Oct 13, 2005
Posts: 46368
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.


SCJP 1.6(91%), SCWCD 1.5(100%), SCBCD in progress
I agree. Here's the link:
subject: Base class private
jQuery in Action, 3rd edition