Home » Java Aptitude Que. & Ans.

Java conditional statements Aptitude Questions and Answers

This section contains Aptitude Questions and Answers on Java Conditional Statements like if else, switch case statement, conditional statements etc.

List of Java Conditional Statements Aptitude Questions

1) Consider the code snippet and select the correct output
if(true && false && true || false)
	System.out.println("True.");
else
	System.out.println("False");
  1. True.
  2. False.

2) What will be the output of following program?
public class temp
{
	public static void main(String args[])
	{
		int x=1;		
		if((boolean)x==true)
			System.out.println("True.");
		else
			System.out.println("False.");
		
	}
}
  1. True.
  2. False.
  3. Error

3) What will be the output of following program ?
public class temp
{
	public static void main(String args[])
	{
		int ok=10;
		switch(ok)
		{
			default:
				System.out.println("default");
			case 0:
				System.out.println("true");
			case 1:
				System.out.println("false");
		}
	}
}

  1. default
  2. Error
  3. true false default
  4. default true false

4) What will be the output of following program?
public class temp
{
	public static void main(String args[])
	{
		boolean ok=true;
		switch(ok)
		{
			case true:
				System.out.println("true");
			break;
			case false:
				System.out.println("false");
			break;
			default:
				System.out.println("default");
			break;
		}		
	}
}
  1. Error
  2. true
  3. false
  4. default

5) What will be the output of following program ?
public class temp
{
	public static void main(String args[])
	{
		int x=1;	
		if(x)
			System.out.println("True");
		else
			System.out.println("False");
	}
}
  1. True
  2. False
  3. Error

Page 2



Comments and Discussions!

Load comments ↻





Copyright © 2024 www.includehelp.com. All rights reserved.