Professional Documents
Culture Documents
What Is Printed Out Following The Execution of The Code Below ?
What Is Printed Out Following The Execution of The Code Below ?
1. class Test {
2.
static String s;
3.
4.
int x = 4;
5.
if (x < 4)
6.
7.
else
8.
System.out.println(s);
9.
10. }
Nothing. The code fails to compile because the String s isnt declared correctly.
The text "Val = null" is displayed.
The text "null" is displayed.
Runtime error due to NullPointer exception.
Topic: Access Modifiers
Analyse the following 2 classes and select the correct statement.
class A {
private int x = 0;
static int y = 1;
protected int q = 2;
}
class B extends A {
void method() {
System.out.println(x);
System.out.println(y);
System.out.println(q);
}
}
The code fails to compile because the variable x is not available to class B.
The code compiles correctly, and the following is displayed: 0 1 2
The code fails to compile because you cant subclass a class with protected
variables.
The code fails to compile because you cant subclass a class with static variables.
Topic: Access Modifiers
Given the following class, which of these is valid way of referring to the
class from outside of the package com.test?
package com.test;
public class MyClass {
// ...
}
By simply referring to the class as MyClass.
By simply referring to the class as test.MyClass.
By simply referring to the class as com.test.MyClass.
By importing with com.* and referring to the class as test.MyClass.
Topic: Access Modifiers
Given the following member declarations, which statement is true?
int a;
// (1)
static int a;
// (2)
// (3)