Question
Refer to the following classes. public abstract class Alpha { private int value = 4; public Alpha( ) { } public abstract String display( );
Refer to the following classes.
public abstract class Alpha
{
private int value = 4;
public Alpha( )
{ }
public abstract String display( );
public void setValue( )
{ value = n; }
public int getValue( )
{ return value; }
}
public class Beta extends Alpha
{
private int num;
public Beta(int myNum)
{
super( );
num = myNum;
super.setValue(myNum - 3);
}
public String display( )
{
return "value: " + getValue( ) + " num: " + num;
}
}
public class Gamma extends Alpha
{
private int num;
public Gamma(int myNum)
{
super( );
num = myNum;
}
public String display( )
{
return "num: " + num + " value: " + getValue( );
}
}
Consider the following code segment in the main method of another class.
Alpha bObject = new Beta(5);
Alpha gObject = new Gamma(6);
System.out.println(bObject.display( ));
System.out.println(gObject.display( ));
Which is printed as a result of executing the code segment?
Question 1 options:
1 | value: 2 num: 5 value: 2 num: 5 |
2 | value: 2 num: 5 num: 6 value: 3 |
3 | value: 2 num: 5 value: 3 num: 6 |
4 | value: 2 num: 5 value: 4 num: 6 |
5 | value: 2 num: 5 num: 6 value: 4 |
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started