Java Object Oriented Programming Quiz 4

Java object oriented programming quiz part 4 contains 10 single and 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 4 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{
    	void Two(){
    		System.out.print("Two,");
    	}
    }
    class Three extends Two{
    	public Three(){
    		System.out.print("Three,");
    	}
    }
    
    public class Test{
    	
    	public static void main(String[] args){
    		Three three = new Three();
    	}		
    }
    
  2. What all method1 method declarations are valid for TestChild class at the line number 11?

    class TestException extends Exception{}
    class TestChild1Exception extends TestException{}
    class TestChild2Exception extends TestChild1Exception{}
    
    public class Test{
    	public void method1() throws TestChild1Exception{
    	}
    }
    
    class TestChild extends Test{
    	//method declaration here
    }
    
  3. What will happen when you compile and run the following code?

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

    abstract class Test{	
    	public void something(){
    		System.out.println("Something");
    	}
    	
    	abstract public void nothing();
    }
    
  5. What will happen when you compile and run the following code?

    public class Test{
    	
    	public static void main(String[] args){
    		
    		boolean b1 = true;
    		boolean b2 = true;
    
    		if(b1 == b2){
    			System.out.print("==");
    		}
    
    		if(b1.equals(b2)){
    			System.out.print("equals");
    		}
    	}
    }
    
  6. What will happen when you compile and run the following code?

    public class Test{
    	
    	static String name = "Test";
    
    	public Test(){
    		name = "TestObject";
    	}
    	
    	public static void main(String[] args){	
    		System.out.println("Name is " + name);
    	}	
    }
    
  7. What will happen when you compile and run the following code?

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

    abstract class One{
    	public One(){
    		System.out.println("One");
    	}
    	
    	abstract void nothing();
    }
    
    public class Test{
    	public static void main(String[] args) {
    		One one = new One();
    	}
    }
    
  9. 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(){
    		System.out.print("Hi,");
    	}
    }
    
    public class Test{
    	public static void main(String[] args) {
    		Two two = new Two();
    	}
    }
    
  10. 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(){
    		System.out.print("Hi,");
    		super("Two");
    	}
    }
    
    public class Test{
    	public static void main(String[] args) {
    		Two two = new Two();
    	}
    }