1) Which of the following statement is true?
A. A source file can have any no. of public classes.
B. A file can have only one package statement.
C. File with public classes have no naming restrictions.
D. The package statement must come after the import statement and before the class declaration.
2) Which of the following identifier is valid?
A. true
B. $_$
C. null
D. void
3) Which of the following is not a valid identifier?
A. __args
B. $null
C. _$_123
D. main
4) Which of the following is a keyword in Java?
A. main
B. args
C. assert
D. Demo
5) Which of the following statement is valid?
A. byte a=25;
B. float b=3.94;
C. integer c=24;
D. character d='A';
6) Given:
1. long a=24;
2. float b=a;
3. int c=(int)b;
4. byte d=c;
5. System.out.println(d);
What is the result?
A. 24
B. 24.0
C. Compilation fails due to an error on line 1
D. Compilation fails due to an error on line 2
E. Compilation fails due to an error on line 3
F. Compilation fails due to an error on line 4.
7) Given:
1. byte a=2;
2. short b=1;
3. char c='a';
4. int d=a+b+c;
5. System.out.println(d);
What is the result?
A. 100
B. d
C. 97
D. a3
E. Compilation fails due to an error on line 4.
F. Compilation fails due to an error on line 5.
8) Given:
1. class Demo {
2. public static void main(String args[]) {
3. int a=3;
4. while(a++<=13);
5. System.out.println(++a);
6. } }
What is the result?
A. 14
B. 15
C. 16
D. 17
E. 18
F. Compilation fails due to an error on line 4
9) Given:
1. class Demo {
2. public static void main(String args[]) {
3. int a=5,b=5;
4. if((a++>b)&&(a>++b)) {
5. System.out.println(a);
6. } } }
What is the result?
A. 5
B. 6
C. 7
D. 10
E. No Output
F. Compilation fails due to an error on line 4
10) Given:
1. int a=5;
2. short b=3;
3. char c=2;
4. c+=a*b;
5. int d=c;
6. System.out.println(d);
What is the result?
A. Compilation fails due to an error on line 3
B. Compilation fails due to an error on line 4
C. Compilation fails due to an error on line 5
D. 17
E. 21
F. 25
11) Given:
1. int x = 0;
2. int y = 10;
3. do {
4. y--;
5. ++x;
6. } while (x < 5);
7. System.out.print(x + "," + y);
What is the result?
A. 5,6
B. 5,5
C. 6,5
D. 6,6
E. Compilation fails due to an error on line 6
F. Compilation fails due to an error on line 7
12) Given:
1. class Demo {
2. public static void main(String args[]) {
3. boolean TRUE=true;
4. if(TRUE==true)
5. System.out.println(true);
6. else
7. System.out.println(TRUE);
8. } }
What is the result?
A. true
B. TRUE
C. Compilation fails due to an error on line 3
D. Compilation fails due to an error on line 4
E. Compilation fails due to an error on line 5
F. Compilation fails due to an error on line 7
13) Given:
1. class Demo {
2. public static void main(String args[]) {
3. int a=5;
4. while(true) {
5. if(a++<8)
6. continue;
7. if(a>8)
8. break;
9. System.out.println(a);
10. } } }
What is the result?
A. 8
B. 5 6 7
C. 7 8
D. 6 7 8
E. No Output
F. None of the above
14) Given:
1. class Demo {
2. public static void main(String[] args) {
3. for(int __x = 0; __x < 3; __x++) ;
4. int x=10;
5. short y=20;
6. y+=x;
7. System.out.println(y);
8. } }
What is the result? (Choose all that apply.)
A. Compilation succeeds
B. Compilation fails with an error on line 3
C. Compilation fails with an error on line 4
D. Compilation fails with an error on line 5
E. Compilation fails with an error on line 6
F. Compilation fails with an error on line 7
15) Which set of operators represents the complete set of valid Java assignment operators?
A. %=, &=, *=, $=, :=, /=, ^=, |=, +=, <<=, =, -=, >>=
B. ~=, &=, *=, /=, ^=, |=, +=, <<=, =, -=, >>=
C. %=, &=, *=, /=, ^=, |=, +=, <<=, =, -=, >>=
D. %=, &=, *=, $=, /=, :=, |=, +=, <<=, =, -=, >>=
16) Given:
1. class Demo {
2. public static void main (String[] args) {
3. boolean booleanValue1 = true;
4. boolean booleanValue2 = false;
5. System.out.print(!(booleanValue1 && !booleanValue2) + ", ");
6. System.out.print(!(booleanValue1 || !booleanValue2)+ ", ");
7. System.out.print(!booleanValue1); } }
What will be printed?
A. false, false, true
B. false, true, true
C. true, false, true
D. true, true, true
E. false, false, false
F. true, false, false
17) Given:
1. class Demo {
2. public static void main(String[] args) {
3. int a=1;
4. switch(a) {
5. default: System.out.print("Invalid");
6. case 1: System.out.print("One");
7. case 2: System.out.print("Two"); break;
8. case 3: System.out.print("Three");
9. } } }
What will be printed?
A. OneTwoThreeInvalid
B. OneTwoThree
C. OneTwo
D. One
E. InvalidOneTwoThree
F. InvalidOneTwo
18) Which of the following options contain correct code to declare and initialize variables to store whole numbers? (Choose all that apply.)
A. bit a1 = 0;
B. integer a2 = 7;
C. long a3 = 0x10C;
D. float a7 = 3.5;
19)Given
1. public class Demo {
2. public static void main(String[] args) {
3. int a = 10;
4. long b = 20;
5. short c = 30;
6. System.out.println(++a + b++ * c);
7. } }
What will be the result?
A. 611
B. 641
C. 930
D. 960
E. Compilation fails due to an error on line 4
F. Compilation fails due to an error on line 6
20) Given
1. class Demo {
2. public static void main(String[] args) {
3. int a=5;
4. int b=a++ + ++a;
5. System.out.println(a+"\t"+b);
6. } }
What will be the result?
A. 7 12
B. 6 12
C. 7 10
D. 6 10
E. Compilation fails due to an error on line 4
Answers:
1) B 2) B 3) D 4) C 5) A 6) F 7) A 8) C 9) E 10) D
11) B 12) A 13) E 14) A 15) C 16) E 17) C 18) C 19) A 20) A
No comments:
Post a Comment