Skip to content

Java Object Oriented Programming Quiz 9

Java object oriented programming quiz part 9 contains 10 single choice questions. The Java OOPs questions will help you understand the OOPs concepts of the Java language. At the end of the quiz, result will be displayed along with your score and OOPs quiz answers online.

There is no time limit to complete the quiz. Click Start Quiz button to start the Java object oriented programming quiz 9 online.

  1. What all variables you can access at line 12?

    public class Test{
    	private int i = 1;
    	int j = 2;
    	
    	public void TestMethod(){
    		
    		class TestInner{
    			
    			int k = 3;
    			final int l = 4;
    			public void InnerMethod(int m){
    				System.out.println(//variable name here);
    			}
    		}
    	}
    }
    
  2. What all variables you can access at line 9?

    public class Test{		
    
    	int x = 0;
    	static int y = 1;
    
    	static class InnerClass{
    		int z = 2;
    		public void getValue(){
    			//access variable here
    		}
    	}
    }
    
  3. An inner class can be declared private.

  4. Will this code compile without any errors?

    public class Main{		
    
    	public void TestMethod(){
    		int a = 0;
    		class TestInner{
    			public void InnerMethod(final int x, int y){
    				System.out.println(a);
    			}
    		}
    	}
    }
    
  5. Will this code compile without any errors?

    public class Test{		
    
    	class InnerClass{
    		static int z = 1;		
    	}
    }
    
  6. Will this code compile without any errors?

    public class Test{		
    
    	public void TestMethod(){
    		
    		static class TestInner{
    			int x = 0;
    		}
    	}
    }
    
  7. Will this code compile without any errors?

    public class Test{		
    
    	public void method1(){
    		
    		class TestInner{
    			public int x = 0;
    		}
    		
    	}
    	
    	public void method2(){
    		TestInner inner = new TestInner();
    		System.out.println(inner.x);
    	}
    }
    
  8. Will this code compile without any errors?

    public class Test{		
    
    	static int i = 0;
    	int j = 1;
    	
    	public void TestMethod(){
    		class TestInner{
    			public void InnerMethod(){
    				System.out.println(i);
    			}
    		}
    	}
    }
    
  9. Will this code compile without any errors?

    public class Test{		
    
    	public class TestInner{
    		public void print(){
    			System.out.println("Hi");
    		}
    	}
    	public static void main(String[] args) {
    		TestInner testInner = new TestInner();
    		testInner.print();
    	}
    }
    
  10. A top level class cannot be static but inner class can be.