Win a copy of Design for the Mind this week in the Design forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

top lavel static clas

 
Hema chowdary
Greenhorn
Posts: 18
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.process();
}

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
Posts: 192
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
This works.



 
Jesper de Jong
Java Cowboy
Saloon Keeper
Posts: 15214
36
Android IntelliJ IDE Java Scala Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.

Regards,
Jesper Young
Bartender (forum moderator)
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic