Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people, just like you, are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
Solved

Base calss private

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

Come see why top tech companies like Mailchimp and Media Temple use Linux Academy to build their employee training programs.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
jar file executable 12 58
servlet example issue 6 46
arguments to jar 5 35
Error in @AspectJ Based AOP with Spring 2 18
An old method to applying the Singleton pattern in your Java code is to check if a static instance, defined in the same class that needs to be instantiated once and only once, is null and then create a new instance; otherwise, the pre-existing insta…
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…
Viewers learn about the “for” loop and how it works in Java. By comparing it to the while loop learned before, viewers can make the transition easily. You will learn about the formatting of the for loop as we write a program that prints even numbers…
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:

856 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