Solved

Base calss private

Posted on 2011-03-25
5
287 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

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

INTRODUCTION Working with files is a moderately common task in Java.  For most projects hard coding the file names, using parameters in configuration files, or using command-line arguments is sufficient.   However, when your application has vi…
Java functions are among the best things for programmers to work with as Java sites can be very easy to read and prepare. Java especially simplifies many processes in the coding industry as it helps integrate many forms of technology and different d…
Viewers will learn about if statements in Java and their use The if statement: The condition required to create an if statement: Variations of if statements: An example using if statements:
This tutorial covers a practical example of lazy loading technique and early loading technique in a Singleton Design Pattern.

760 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

Need Help in Real-Time?

Connect with top rated Experts

20 Experts available now in Live!

Get 1:1 Help Now