ExamVeda
Login
Home
Data Types and Variables
?

What is the output of the following program?
public class Test{
	static int x  = 10 ;
       	public static void main(String[] a){
		 Test test = new Test( ) ; 
		 Test test1 = new Test( ) ;
		 test.x  +=  1 ;
		 System.out.println(  test.x + test1.x ) ;    
	}
}

Answer & Solution
Correct Answer: Option C

Static variable have a single copy of memory. That means all the objects will share the same memory location. So, if the object test increase the value of x by 1, then object test1 will access that incremented value of x

Examveda
Question posted by Examveda
Community

Join the Discussion

1 Comment
Ubaid Khan
Ubaid Khan 8 years ago
test.x+=1;
should do x=11.