Solved

Base calss private

Posted on 2011-03-25
5
291 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
[X]
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
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

Webinar: Aligning, Automating, Winning

Join Dan Russo, Senior Manager of Operations Intelligence, for an in-depth discussion on how Dealertrack, leading provider of integrated digital solutions for the automotive industry, transformed their DevOps processes to increase collaboration and move with greater velocity.

Question has a verified solution.

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

Suggested Solutions

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…
Introduction This article is the last of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article covers our test design approach and then goes through a simple test case example, how …
Viewers learn about the third conditional statement “else if” and use it in an example program. Then additional information about conditional statements is provided, covering the topic thoroughly. Viewers learn about the third conditional statement …
Viewers will learn how to properly install Eclipse with the necessary JDK, and will take a look at an introductory Java program. Download Eclipse installation zip file: Extract files from zip file: Download and install JDK 8: Open Eclipse and …

740 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