Skip to content

Java Language Basics Quiz Online Test – 2

Java language basics quiz 2 contains 10 single and multiple choice questions. Java language basics quiz 2 questions are designed in such a way that it will help you understand the basic concepts of Java language. At the end of the quiz, result will be displayed along with your score and Java language basics quiz answers.

There is no time limit to complete the quiz. Click Start Quiz button to start the Java language basics quiz online.

  1. 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");
    	}	
    }
    
  2. What will happen when you compile and run the following code?

    public class Test{
    	
    	public static void main(String[] args){
    		
    		MyMathClass m = new MyMathClass();
    		
    		int i=10, j=15;
    		m.sum(i, j);
    		
    		float f1=3.4f, f2=9.23f;
    		m.sum(f1, f2);
    		
    		char c1='a', c2='b';
    		m.sum(c1, c2);
    	}	
    }
    
    class MyMathClass{
    	
    	public void sum(int i1, int i2){
    		System.out.print(":int");
    	}
    	
    	public void sum(String str1, String str2){
    		System.out.print(":String");
    	}
    	
    	public void sum(double d1, double d2){
    		System.out.print(":double");
    	}
    }
    
  3. 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");
    	}	
    }
    
  4. What will happen when you compile and run the following code?

    public class Test{
    	
    	public static void main(String[] args){				
    		boolean b1 = false, b2 = null;
    		System.out.println( b1 && b2);
    	}	
    }
    
  5. Which of the following statements, if written at the line 11 will compile without error?

    public class Test{
    	
    	public static void main(String[] args){			
    		int i = 5;
    		long l = 50;
    		char c = 'a';
    		float f = 0.5f;
    		double d = 32.4323;
    		String s = "b";
    		
    		//code here
    	}	
    }
    
  6. Will this code compile without error?

    public class Test{	
    	public native int getArea(int w, int h);
    }
    
  7. Will this code compile without error?

    interface Test {
    	abstract public void someMethod() throws Exception;
    }
    
  8. What will happen when you compile and run the following code?

    public class Test{
    	
    	public static void main(String[] args){			
    		int i = 5, j = null;
    		System.out.println( i % j );		
    	}	
    }
    
  9. 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();
    }
    
  10. What will happen when you compile and run the following code?

    public class Test{
    	
    	public static void main(String[] args) {
    		
    		int i = 10, j = 5;
    		System.out.println(compute(i, j));
    	}
    	
    	public int compute(int i, int j){
    		if(j == 0)
    			return 0;
    		else
    			return i / j;
    	}
    }