Solved

Base calss private

Posted on 2011-03-25
5
289 Views
Last Modified: 2012-06-21
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.
0
Comment
Question by:gudii9
5 Comments
 
LVL 92

Accepted Solution

by:
objects earned 250 total points
ID: 35220322
you cannot have a private top level class in Java
0
 
LVL 14

Expert Comment

by:CPColin
ID: 35220469
The example class is a little misleading. A "top-level class" is different from a "base class." Top-level classes are those not nested inside other classes and, as objects mentioned above, cannot be private. This is because having a private top-level class would mean no other code could access it.
0
 
LVL 20

Assisted Solution

by:Sathish David Kumar N
Sathish David  Kumar N earned 125 total points
ID: 35221403
>>>>>>>>>we are not extending Base class right. Why still it complain.

ok what you will do with that class
you cant create instances because its a private u cant extend . so the class is no use right ??

waste of memeory !
0
 
LVL 7

Author Comment

by:gudii9
ID: 35368861
>>> A "top-level class" is different from a "base class."

what is difference between base and top-level class. I do not see extend also in this example.

private class Base{}
is just simply sitting
0
 
LVL 14

Assisted Solution

by:CPColin
CPColin earned 125 total points
ID: 35368916
A top-level class is one that is not nested inside another class. A base class is one that is extended by a derived class. In this case, somebody named the top-level class "Base," which is confusing. Ignore everything about extending and just focus on the fact that a top-level class, that is, one that is not nested inside another class, cannot be private.
0

Featured Post

Master Your Team's Linux and Cloud Stack!

The average business loses $13.5M per year to ineffective training (per 1,000 employees). Keep ahead of the competition and combine in-person quality with online cost and flexibility by training with Linux Academy.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
why cannot we forward request once the response is committed 2 42
varialbe initialization 11 33
Why my table column Id is not passed to java object? 4 39
ejb on wildfly 5 20
Java Flight Recorder and Java Mission Control together create a complete tool chain to continuously collect low level and detailed runtime information enabling after-the-fact incident analysis. Java Flight Recorder is a profiling and event collectio…
Introduction This article is the second of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article covers the basic installation and configuration of the test automation tools used by…
Viewers learn about the scanner class in this video and are introduced to receiving user input for their programs. Additionally, objects, conditional statements, and loops are used to help reinforce the concepts. Introduce Scanner class: Importing…
This tutorial covers a practical example of lazy loading technique and early loading technique in a Singleton Design Pattern.

773 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question