Topic: Access Modifiers Given The Following Code, Which Statement Can Be Placed at The Indicated Position Without Causing Compilation Errors?

You might also like

Download as doc, pdf, or txt
Download as doc, pdf, or txt
You are on page 1of 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.

You might also like