1. Name two situations in which you would use the reserved word super.
2. Consider the following class definition:
public class AClass
{
private int u;
private int v;
public void print()
{
}
public void set(int x, int y)
{
}
public AClass()
{
}
public AClass(int x, int y)
{
}
}
What is wrong with the following class definition?
class BClass AClass
{
private int w;
public void print()
{
System.out.println(“u + v + w = “ + (u + v + w);
}
public BClass()
{
super();
W = 0;
}
public BClass(int x, int y, int z)
{
super(x, y);
w = z;
}
}
3. Consider the following statements:
public class YClass
{
private int a;
private int b;
public void one()
{
}
public void two(int x, int y)
{
}
public YClass()
{
}
}
class XClass extends YClass
{
private int z;
public void one()
{
}
public XClass()
{
}
}
YClass yObject = new YClass();
XClass xObject = new XClass();
a. The private members of YClass are public members of XClass. True or False, briefly explains?
b. Mark the following statements as valid or invalid. If a statement is invalid, explain why.
i. The following is a valid definition of the method one of YClass.
public void one()
{
System.out.println(a + b);
}
ii.
yObject.a = 15;
xObject.b = 30;
iii. The following is a valid definition of the method one of XClass.
Public void one()
{
a = 10;
b = 15;
z = 30;
System.out.println(a + b + z);
}
iv.
System.out.println(yObject.a + “ “ + yObject.b + “ “ + xObject.z);
Name two situations in which you would use the reserved word super
- Technology: Multiple-Choice-Questions
- Code: SHC_MCQ_10000
-
$9.99
Tags: Multiple choice question, MCQ, java