Вы находитесь на странице: 1из 2

Topic: Access Modifiers

Given the following code, which statement can be placed at the indicated
position without causing compilation errors?
public class ThisUsage {
int planets;
static int suns;
public void gaze() {
int i;
// ... insert statements here ...
}
}
this = new ThisUsage();
this.i = 4;
this.planets = i;
i = this.planets;
Topic: Access Modifiers
Given the following:
class Gamma {
public int display() {
return 3;
}
}
public class Delta extends Gamma {
@Override
protected int display() {
return 4;
}
}

What will be the result of compiling the above code ?


The code compiles correctly without any errors.
The code fails to compile, because you cant override a method to be more private
than its parent.
The code fails to compile, because @Override cannot be mentioned above a
protected method.
The code fails to compile, because public methods cannot be overriden.
Topic: Access Modifiers
Given the following:
class TestAccess {
public int calculate() {
int a=5,b=6;
return a+b;
}
}
public class MyChild extends TestAccess {
@Override
int calculate() {
return 100;
}
}
What will be the result of compiling the above code ?
The code fails to compile, because you cant override a method to be more private
than its parent.
The code fails to compile, because @Override cannot be mentioned above a default
method.
The code fails to compile, because public methods cannot be overriden.
The code compiles correctly without any errors.

Вам также может понравиться