File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes top lavel static clas Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "top lavel static clas" Watch "top lavel static clas" New topic

top lavel static clas

Hema chowdary

Joined: Mar 17, 2009
Posts: 18
static class A {
void process() throws Exception { throw new Exception(); }
static class B extends A {
void process() { System.out.println("B "); }
public static void main(String[] args) {
A a = new B();

A. B
B. The code runs with no output.
C. An exception is thrown at runtime.
D. Compilation fails because of an error in line 15.
E. Compilation fails because of an error in line 18.
F. Compilation fails because of an error in line 19.

They have given the answer is F.But here static modifier is not allowed to a top level class.So the answer should be Compilation fails.Then F is wrong.Please clarify me.

Ryan Beckett
Ranch Hand

Joined: Feb 22, 2009
Posts: 192
This works.

Jesper de Jong
Java Cowboy
Saloon Keeper

Joined: Aug 16, 2005
Posts: 15082

Hello "Apple Java", welcome to JavaRanch.

First, you have to pay attention to two administrative things.

1. We have a naming policy on JavaRanch. Obviously fake names like "Apple Java" are not allowed here. Please read the naming policy carefully and change your display name by editing your profile.

2. When you copy a question from a mock exam, book or other source, we require that you quote your sources. So, please tell us where you copied this question from.

Jesper Young
Bartender (forum moderator)

Java Beginners FAQ - JavaRanch SCJP FAQ - The Java Tutorial - Java SE 8 API documentation
I agree. Here's the link:
subject: top lavel static clas
It's not a secret anymore!