Question: Given the following classes: public class A { private int x = 1 5 public class B extends A private int x = 1 0

Given the following classes:
public class A {
private int x =15
public class B extends A private int x =100 ; private int z =200
private int y =30
public int sum(){ return x + y
public int sum(){
return super.sum() z
}
public int getX (){ return this.x;
public int getX20( return this.getX()*this.x;
}
} Consider the following code:
B a1= new B(); A a2= new B0);
For each expression below, indicate the result of the expression. Write "Illegal" for the result if the expression is not allowed.
EXPRESSION
1) a2.getX()
2)((B)a2).getX()
3)a2.getX2()
4)((B)a2).getX2()
5)a1.sum()

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!