Skip to content

Java If Else Quiz Online Test

Java If Else Quiz contains 10 single and multiple choice questions. If else quiz questions are designed in such a way that it will help you understand how if else statement works in Java. At the end of the quiz, result will be displayed along with your score and if else quiz answers.

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

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

    public class Test {
        
        public static void main(String[] args){        
            
            String state = "on";
            
            if(state = "on")
                System.out.println("On");
            else
                System.out.println("Off");
            
        }
    }
    
  2. What will happen when you compile and run the following code?

    public class Test {
    	
    	public static void main(String[] args){		
    		
    		int temperature = 33;
    	
    		if(temperature < 0)
    			System.out.println("Freezing");
    		else if(temperature < 30)
    			System.out.println("Pleasant");
    		else if(temperature < 50)
    			System.out.println("Hot");
    		else
    			System.out.println("Boiling");
    	
    	}
    }
    
  3. What will happen when you compile and run the following code?

    public class Test {
    	
    	public static void main(String[] args){		
    		
    		int i = 51;
    		
    		if(i > 50)
    			System.out.println("Greater than 50");
    		else
    			System.out.println("Less than 50");
    			System.out.println("Done");
    		
    	}
    }
    
  4. What will happen when you compile and run the following code?

    public class Test {
    	
    	public static void main(String[] args){		
    		
    		int i = 49;
    
    		if(i > 50)
    			System.out.println("Greater than 50");
    			System.out.println("Great");
    		else
    			System.out.println("Less than 50");
    	
    	}
    }
    
  5. What will happen when you compile and run the following code?

    public class Test {
    	
    	public static void main(String[] args){		
    		
    		int i = 49;
    
    		if(i < 50){
    			System.out.println("Greater than 50");
    			System.out.println("Great");
    		}else
    			System.out.println("Less than 50");
    	
    	}
    }
    
  6. What will happen when you compile and run the following code?

    public class Test {
    	
    	public static void main(String[] args){		
    		
    		boolean a = true, b = false;
    		
    		if(a && !b) System.out.println("true");
    		else System.out.println("false");
    		
    	}
    }
    
  7. What will happen when you compile and run the following code?

    public class Test {
    	
    	public static void main(String[] args){		
    		
    		int a = 25;
    		if(a < 25)
    			System.out.println("1");
    			if(a > 10)
    				System.out.println("2");
    		else
    			System.out.println("3");
    		
    	}
    }
    
  8. What will happen when you compile and run the following code?

    public class Test {
    	
    	public static void main(String[] args){		
    		
    		int a = 23, b = 30;
    		
    		if(a > 20 && b > 25)
    			System.out.println("1");
    		if(a > 30 && b < 35)
    			System.out.println("2");
    		else
    			System.out.println("3");
    		
    	}
    }
    
  9. Select all true statements from the following statements

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

    public class Test {
    	
    	public static void main(String[] args){		
    		
    		int a = 2 * 22 + 13 - 21;
    		int b = 15 * 3 + 17 - 12;
    		
    		if(a > b);
    			System.out.println("Greater");
    		else
    			System.out.println("Less");		
    	}
    }