Examveda
Examveda

What will be the output?
public class Test{
	static{
		int a = 5;
	}

	public static void main(String args[]){
		new Test().call();
	}

	void call(){
		this.a++;
		System.out.print(this.a);
	}
}

A. Compile with error

B. Runtime Exception

C. 5

D. 6

E. 0

Answer: Option A


This Question Belongs to Java Program >> Declaration And Access Control

Join The Discussion

Comments ( 4 )

  1. Manoj Kumar
    Manoj Kumar :
    6 years ago

    bcause scope of variable a is limited to static block. outside the static block variable a has not identification.

  2. Siva Kumaran
    Siva Kumaran :
    7 years ago

    the variable 'a' in static block cannot able to access using this keyword

  3. Siva Kumaran
    Siva Kumaran :
    7 years ago

    why compile time error

  4. Abhishek Kanth
    Abhishek Kanth :
    8 years ago

    Why explain old

Related Questions on Declaration and Access Control