ExamVeda
Login
Home
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);
    } 
}
Discuss
Answer & Solution
Answer: Option D
Solution:
The correct answer is D: Compilation error.
Here's why:
In Java, variables have a scope, which determines where they can be accessed in the code.
'x' is declared outside the inner block, so it's accessible both inside and outside the curly braces {}.
'y' is declared inside the inner block {}. This means 'y' is only accessible within that block.
The line 'System.out.println(x + " " + y);' is outside the inner block where 'y' is defined.
Therefore, the compiler will give an error because it cannot find a variable named 'y' in that scope.
The program will not compile because of the scope issue with the variable 'y'.
2
What does LocalTime represent?
Discuss
Answer & Solution
Answer: Option B
No explanation is given for this question. Let's Discuss on Board
3
What will be the output of the following Java program?
class mainclass {
    public static void main(String args[]) 
    {
        char a = 'A';
        a++;
  System.out.print((int)a);
    } 
}
Discuss
Answer & Solution
Answer: Option A
No explanation is given for this question. Let's Discuss on Board
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);
	}
}
Discuss
Answer & Solution
Answer: Option B
No explanation is given for this question. Let's Discuss on Board
5
What will be the output of the following Java code?
enum Season 
{
    WINTER, SPRING, SUMMER, FALL
};
System.out.println(Season.WINTER.ordinal());
Discuss
Answer & Solution
Answer: Option A
No explanation is given for this question. Let's Discuss on Board
6
Which of these coding types is used for data type characters in Java?
Discuss
Answer & Solution
Answer: Option C
No explanation is given for this question. Let's Discuss on Board
7
What is Truncation in Java?
Discuss
Answer & Solution
Answer: Option A
No explanation is given for this question. Let's Discuss on Board
8
Which of these occupy first 0 to 127 in Unicode character set used for characters in Java?
Discuss
Answer & Solution
Answer: Option D
No explanation is given for this question. Let's Discuss on Board
9
How to convert Date object to String?
Discuss
Answer & Solution
Answer: Option B
No explanation is given for this question. Let's Discuss on Board
10
What will be the output of the following Java program?
    class c 
    {    
        public void main( String[] args ) 
        {  
            System.out.println( "Hello" + args[0] ); 
        } 
    }
Discuss
Answer & Solution
Answer: Option D
No explanation is given for this question. Let's Discuss on Board