Share on Google+Share on Google+

SCJP Module-1 Question-7

Advertisement
The program given below shows the feature of static block and their execution time in program and is very helpful for the SCJP examinations

Given a sample code:

1 abstract class Ball {
2 static {
3 int value = 10;
4 System.out.println("value = " + value);
}}

5 class Football extends Ball {
}

6 public class Sample2 {
7 public static void main(String args[]) {
8 new Football();
}}

What will be the result?

(1) Compilation succeeds but cause runtime error
(2) Compilation succeeds and give output 10
(3) Compilation fails because of an error at line 5
(4) Compilation fails because of line no 8

Answer

(2)

Explanations

This program execute with printing the output 10 on console.

Advertisements

Posted on: July 7, 2010 If you enjoyed this post then why not add us on Google+? Add us to your Circles

Share this Tutorial Follow us on Twitter, or add us on Facebook or Google Plus to keep you updated with the recent trends of Java and other open source platforms.