Java Object Oriented Programming Quiz 3

Java object oriented programming quiz part 3 contains 10 single multiple 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 3 online.

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

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

    class One{
    	private void callMe(){
    		System.out.println("Parent");
    	}
    	
    	public void caller(){
    		callMe();
    	}
    }
    class Two extends One{
    	public void callMe(){
    		System.out.println("Child");
    	}
    }
    
    public class Test{
    	
    	public static void main(String[] args){	
    		Two two = new Two();
    		two.caller();
    	}		
    }
    
  3. What will happen when you compile and run the following code?

    class One{
    	public void callMe(){
    		System.out.println("Parent");
    	}
    	
    	public void caller(){
    		callMe();
    	}
    }
    class Two extends One{
    	public void callMe(){
    		System.out.println("Child");
    	}
    }
    
    public class Test{
    	
    	public static void main(String[] args){	
    		Two two = new Two();
    		two.caller();
    	}		
    }
    
  4. A private method defined in the parent class cannot be overridden by child class.

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

    class One{
    	public int method(){
    		System.out.println("int");
    		return 0;
    	}
    }
    class Two extends One{
    	public short method(){
    		System.out.println("short");
    		return 1;
    	}
    }
    
    public class Test{
    	
    	public static void main(String[] args){	
    		One one = new Two();
    		one.method();
    	}		
    }
    
  6. Will the following code compile?

    class One{
    	public void someMethod() throws Exception{
    	}
    }
    class Two extends One{
    	public void someMethod(){
    	}
    }
    
  7. Will the following code compile?

    import java.io.IOException;
    
    class One{
    	public void someMethod() throws IOException{
    	}
    }
    class Two extends One{
    	public void someMethod() throws Exception{
    	}
    }
    
  8. Will the following code compile?

    import java.io.FileNotFoundException;
    import java.io.IOException;
    
    class One{
    	public void someMethod() throws IOException{
    		throw new IOException();
    	}
    }
    class Two extends One{
    	public void someMethod() throws FileNotFoundException{
    		throw new FileNotFoundException();
    	}
    }
    
  9. Does the class Two override the someMethod() correctly?

    class One{
    	public void someMethod(int i){		
    	}
    }
    class Two extends One{
    	public void someMethod(short s){		
    	}
    }
    
  10. Select all method declarations that successfully override the someMethod() defined in the class One?

    class One{
    	public void someMethod(int i) throws Exception{		
    	}
    }
    
    class Two extends One{
    	//method declaration here
    	{
    	}
    }
    

Online Shopping