Win a copy of Programmer's Guide to Java SE 8 Oracle Certified Associate (OCA) this week in the OCAJP 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
Pie
Posts: 49776
69
  • 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