Java Object Oriented Programming Quiz 6

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

  1. Will this code compile?

    public class Test{	
    	public int count(int i){
    		return 0;
    	}
    }
    
    class TestChild extends Test{
    	public int count(long i) throws Exception{
    		return 0;
    	}
    }
    
  2. Will this code compile without error?

    interface Test {
    	abstract public void someMethod() throws Exception;
    }
    
  3. Will this code compile?

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

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

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

    public class Test{
    	
    	class TestInner{
    		void sayHi(){
    			System.out.println("Hi");
    		}
    	}
    	
    	public static void main(String[] args) {
    		TestInner inner = new TestInner();
    		inner.sayHi();
    	}
    }
    
  7. Which class has defined the equals(Object o) method?

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

    public class Test{
    	
    	public static void compute(int i, int j){
    		System.out.println("int version");
    	}
    	
    	public void compute(int i, int j){
    		System.out.println("long version");
    	}
    	
    	public static void main(String args[]){
    		Test t = new Test();
    		compute(10, 5);
    	}	
    }
    
  9. Which of the following variables are accessible at line 13?

    public class Test{
    	
    	private int i = 0;
    	int j = 1;
    	public int k = 2;
    	
    	class TestInner{
    		private int l = 3;
    		int m = 4;
    		public int n = 5;
    		
    		void sayHi(){
    			//access variable here
    		}
    	}
    }
    
  10. What will happen when you compile and run the following code?

    class One{
    	public static void process(){
    		System.out.print("Parent");
    	}
    }
    
    class Two extends One{
    	public static void process(){
    		super.process();
    		System.out.print("Child");
    	}
    }
    
    public class Test{
    	
    	public static void main(String args[]){
    		One one = new Two();
    		one.process();
    	}
    }
    

Online Shopping