Java Object Oriented Programming Quiz 5

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

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

    class One{
    	public One(String name){
    		System.out.print("Hello " + name + ",");
    	}
    }
    
    class Two extends One{
    	public Two(){
    		this("Two");
    		System.out.print("Hi,");
    	}
    }
    
    public class Test{
    	public static void main(String[] args) {
    		Two two = new Two();
    	}
    }
    
  2. What will happen when you compile and run the following code?

    class One{
    	public One(String name){
    		System.out.print("Hello");
    	}
    }
    
    class Two extends One{
    }
    
    public class Test{
    	public static void main(String[] args) {
    		Two two = new Two();
    	}
    }
    
  3. Which of the following classes define the toString() method?

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

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

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

    public class Test{
    	
    	int i;
    	void print(){
    		System.out.println(i);
    	}
    	
    	public static void main(String[] args) {
    		new Test().print();
    	}
    }
    
  7. Will this code compile?

    public class Test{
    	public void count(){		
    	}
    }
    
    class TestChild extends Test{
    	public void count(int i) throws Exception{
    	}
    }
    
  8. What will happen when you compile and run the following code?

    public class Test{
    	
    	public static void main(String[] args){		
    		One o = new Two();
    		o.sayHello();
    	}
    	
    }
    
    final class One{
    	public void sayHello(){
    		System.out.println("Parent Hello");
    	}
    }
    
    class Two extends One{
    	public void sayHello(){
    		System.out.println("Child Hello");
    	}	
    }
    
  9. Will this code compile?

    public class Test{	
    	public int count(int i){
    		return 0;
    	}
    	public long count(int i){
    		return 0;
    	}
    }
    
  10. What will happen when you compile and run the following code?

    public class Test{
    	
    	public static void main(String[] args){		
    		One o = new Two();
    		o.sayHello();
    	}
    	
    }
    
    class One{
    	public final void sayHello(){
    		System.out.println("Parent Hello");
    	}
    }
    
    class Two extends One{
    	public void sayHello(){
    		System.out.println("Child Hello");
    	}	
    }
    

Online Shopping