Java Object Oriented Programming Quiz 8

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

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

    class One{
    	public One(){
    		System.out.print("One");
    	}
    }
    class Two extends One{
    	public Two(){
    		System.out.print("Two");
    	}
    }
    class Three{
    	Two two = new Two();
    	public Three(){
    		System.out.print("Three");
    	}
    }
    public class Test{	
    	
    	public static void main(String[] args) {
    		Three three = new Three();
    	}
    }
    
  2. Can you override public constructor declared in a base class to private in a child class?

  3. A constructor can be final

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

    class TestInner{
    	public void print(){
    		System.out.println("Hi");
    	}
    }
    
    public class Test{
    	public static void main(String[] args) {
    		TestInner t = new TestInner(){
    			public void print(){
    				System.out.println("Hello");
    			}
    		};
    		
    		t.print();
    	}
    }
    
  5. What will happen when you compile and run the following code?

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

    class One{
    	public One(){
    		System.out.print("One");
    	}
    	public One(String str){
    		System.out.print("OneStr");
    	}
    }
    
    class Two extends One{
    	public Two(String str){
    		System.out.print("TwoStr");
    		super(str);
    	}
    }
    
    public class Test{	
    	
    	public static void main(String[] args) {
    		Two two = new Two("Hello");
    	}
    }
    
  7. What will happen when you compile and run the following code?

    public class Test{	
    	
    	public void doNothing(Object object){
    		System.out.println("Object");		
    	}
    	
    	public void doNothing(String string){
    		System.out.println("String");		
    	}
    	
    	public static void main(String[] args) {
    		Test test = new Test();
    		test.doNothing(args);
    	}
    }
    
  8. What will happen when you compile and run the following code?

    public class Test{	
    	
    	public void doNothing(Object object){
    		System.out.println("Object");		
    	}
    	
    	public void doNothing(Integer i){
    		System.out.println("Integer");		
    	}
    	
    	public static void main(String[] args) {
    		Test test = new Test();
    		test.doNothing(null);
    	}
    }
    
  9. What will happen when you compile and run the following code?

    public class Test{	
    	
    	public void doNothing(Object object){
    		System.out.println("Object");		
    	}
    	
    	public void doNothing(Integer i){
    		System.out.println("Integer");		
    	}
    	
    	public void doNothing(Double d){
    		System.out.println("Double");		
    	}
    	
    	public static void main(String[] args) {
    		Test test = new Test();
    		test.doNothing(null);
    	}
    }
    
  10. What will happen when you compile and run the following code?

    public class Test{	
    	
    	public void doNothing(Object object){
    		System.out.println("Object");		
    	}
    	
    	public void doNothing(Integer i){
    		System.out.println("Integer");		
    	}
    	
    	public void doNothing(Double i){
    		System.out.println("Integer");		
    	}
    	
    	public static void main(String[] args) {
    		Test test = new Test();
    		test.doNothing(args);
    	}
    }