Java Language Basics Quiz Online Test – 3

Java language basics quiz 3 contains 10 single and multiple choice questions. Java language basics quiz 3 questions are designed in such a way that it will help you understand the fundamental concepts of Java. 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. Will this code compile without error?

    public class Test{		
    	static native int compute(int i, int j);
    }
    
  2. What will happen when you compile and run the following code?

    public class Test{
    	
    	public static void main(String args[]){
    		
    		byte b1 = 10, b2 = 5;
    		compute(b1, b2);
    	}
    	
    	public static void compute(long l1, long l2){
    		System.out.println("long");
    	}
    	static native void compute(int i, int j){
    		System.out.println("int");
    	}
    }
    
  3. What will happen when you compile and run the following code?

    public class Test{
    	
    	int i = 10;
    	
    	public Test(){
    		i = 20;
    	}
    	
    	public static void main(String args[]){
    		process();
    	}
    	
    	public static void process(){
    		Test t = new Test();
    		System.out.println(this.i);		
    	}
    }
    
  4. Static methods cannot be overloaded

  5. 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);
    	}	
    }
    
  6. 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();
    	}
    }
    
  7. Will this code compile?

    public class Test{
    	
    	static int i = 0;
    	public static void main(String args[]){
    		Test t = new Test();
    		t.print();
    	}
    	
    	public void print(){
    		System.out.println(this.i);
    	}
    }
    
  8. What will happen when you compile and run the following code?

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

    class One{
    	public abstract One();
    }
    
    class Two extends One{
    	public Two(){
    		System.out.println("Two");
    	}
    }
    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{
    	int i = 1;
    	public One(){
    		System.out.println(i);
    	}
    }
    
    class Two extends One{
    	int i = 10;
    	public One(){
    		System.out.println(i);
    	}
    }
    public class Test{
    	
    	public static void main(String[] args) {
    		One one = new Two();
    	}
    }