Menu
Topics Index
...
`

Session 16 has these questions


Scope2611

What will be the output of the following program?
public class Scope {
    public static void main(String[] args) {
        int a = 0;
        {
            int b = 10;
            System.out.println("b = " + b);
            int c = b + a;
            System.out.println("c = " + b);
        }
        a = c + b;
        System.out.println("a = " + a);
    }
}
A. a = 20
b = 10
c = 10
B. b = 10
c = 20
a = 10
C. b = 10
c = 10
a = 20
D. Compilation Error
E. Runtime Error



legal Identifiers

Which of the following can be used in a Java program as identifiers? Check all of the identifiers that are legal.
1. sum_of_data
2. AnnualSalary
3. _average
4. 42isThesolution
5. B4
6. ABC
7. for
8. println
9. "hello"
10. first-name
A. 1, 2 
B. 1, 2, 3
C. 1, 3, 5, 6 
D. 1, 2, 3, 5, 6, 8 
E. 1, 2, 3, 5, 6, 10



Invalid Variable Name

Of the below, what is an invalid variable name?
A. Shiva_Mani_98480_22338
B. 1942_a_love_story
C. Balu_ABCDEFG
D. ___s_ss_ssshh
E. None of the above



Scope of variables2193

What will be the output of the following program?
public class ScopeOfVariables {
    public static void main(String[] args) {
        int x = 10;
        System.out.print(x + ", " + y);
        int y = 20;
        x = 15;
        System.out.print(" - " + x + ", " + y);
    }
}
A. 10, 20 - 15, 20
B. 10, 0 - 15, 20
C. Compilation Error
D. Runtime Error



Identifiers

Identifiers can not starts with?
A. Characters
B. Digits
C. underscore ( _ ) symbols
D. None of the above



Scope

What will be the output of the following program?
public class Scope {
    public static void main(String[] args) {
        int a = 0;
        int b = 10;
        System.out.println("b = " + c);
        int c = b + a;
        System.out.println("c = " + b);
        a = c + b;
        System.out.println("a = " + a);
    }
}
A. a = 20
b = 10
c = 10
B. b = 10
c = 20
a = 10
C. b = 10
c = 10
a = 20
D. Compilation Error
E. Runtime Error



© meritcampus 2019

All Rights Reserved.

Open In App