This week's book giveaway is in the Java in General forum.
We're giving away four copies of Think Java: How to Think Like a Computer Scientist and have Allen B. Downey & Chris Mayfield on-line!
See this thread for details.
Win a copy of Think Java: How to Think Like a Computer Scientist this week in the Java in General forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Base class private

 
Mathew Lee
Ranch Hand
Posts: 238
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 48917
58
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 97
Java MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic