Java Object Oriented Programming Quiz 7

Java object oriented programming quiz part 7 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 7 online.

  1. What will happen when you compile and run the following code?

    public class Test{	
    	private int i = 0;
    	
    	class TestInner{
    		public int i = 1;
    		void sayHi(){
    			System.out.println(i);
    		}
    	}
    	
    	public static void main(String[] args) {
    		TestInner inner = new Test().new TestInner();
    		inner.sayHi();
    	}
    }
    
  2. What will happen when you compile and run the following code?

    class One{
    	public final One(){
    		System.out.print(" One ");
    	}
    }
    
    class Two extends One{
    	public Two(){
    		System.out.print(" Two ");
    	}
    }
    public class Test{
    	
    	public static void main(String[] args) {
    		One one = new One();
    		Two two = new Two();
    	}
    }
    
  3. Will this code compile?

    class Test{
    	interface TestInterface{		
    	}
    }
    
  4. Will this code compile?

    interface TestInterface{
    	class Test{		
    	}
    }
    
  5. What will happen when you compile and run the following code?

    class One{
    	public abstract One();
    }
    
    class Two extends One{
    	public Two(){
    		System.out.println("Two");
    	}
    }
    public class Test{
    	
    	public static void main(String[] args) {
    		Two two = new Two();
    	}
    }
    
  6. Will this code compile?

    interface TestInterface{
    	interface Test{
    	}
    }
    
  7. What will be the generated class file name when you compile the following class?

    public class Test{
    	class TestInner{
    	}	
    }
    
  8. What will happen when you compile and run the following code?

    class One{
    	int i = 1;
    	public One(){
    		System.out.println(i);
    	}
    }
    
    class Two extends One{
    	int i = 10;
    	public One(){
    		System.out.println(i);
    	}
    }
    public class Test{
    	
    	public static void main(String[] args) {
    		One one = new Two();
    	}
    }
    
  9. What will happen when you compile and run the following code?

    class One{}
    class Two extends One{}
    
    public class Test extends One{	
    	
    	public static void main(String[] args) {
    		One one = new One();
    		Two two = new Two();
    		System.out.println(one instanceOf Two);
    	}
    }
    
  10. Is it mandatory to give inner class a name?

Online Shopping