1.
What will be the output of the following Java program?
class variable_scope 
{
    public static void main(String args[]) 
    {
        int x;
        x = 5;
        {
      int y = 6;
      System.out.print(x + " " + y);
        }
        System.out.println(x + " " + y);
    } 
}

4.
What will be the output of the following Java code snippet?
public class AddDemo 
{
	public static void main(String args[]) 
        {
		BigDecimal b = new BigDecimal("23.43");
		BigDecimal br = new BigDecimal("24");
		BigDecimal bres = b.add(new BigDecimal("450.23"));
		System.out.println("Add: "+bres);
 
		MathContext mc = new MathContext(2, RoundingMode.DOWN);
		BigDecimal bdecMath = b.add(new BigDecimal("450.23"), mc);
		System.out.println("Add using MathContext: "+bdecMath);
	}
}

7.
What is Truncation in Java?

9.
How to convert Date object to String?

SimpleDateFormat sdf = new SimpleDateFormat("yyyy-mm-dd");
sdf.parse(new Date());

SimpleDateFormat sdf = new SimpleDateFormat("yyyy-mm-dd");
sdf.format(new Date());

SimpleDateFormat sdf = new SimpleDateFormat("yyyy-mm-dd");
new Date().parse();

SimpleDateFormat sdf = new SimpleDateFormat("yyyy-mm-dd");
new Date().format();

Read More Section(Data Types and Variables)

Each Section contains maximum 100 MCQs question on Data Types and Variables. To get more questions visit other sections.