0% found this document useful (0 votes)
45 views2 pages

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

The code compiles correctly without errors. Local variables declared in a method can only be accessed within that method, so "this.i = 4" would cause a compilation error. The other options either access non-static fields/methods incorrectly or override access incorrectly.

Uploaded by

crazz1
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOC, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
45 views2 pages

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

The code compiles correctly without errors. Local variables declared in a method can only be accessed within that method, so "this.i = 4" would cause a compilation error. The other options either access non-static fields/methods incorrectly or override access incorrectly.

Uploaded by

crazz1
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOC, PDF, TXT or read online on Scribd
You are on page 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.

You might also like