Java Reference
In-Depth Information
YClass yObject;
XClass xObject;
a. The private members of YClass are public members of XClass .
True or False?
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;
iii. xObject.b = 30;
iv. 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);
}
v. System.out.println(yObject.a + " " + yObject.b + " "
+ xObject.z);
11. Assume the declaration of Exercise 10.
a. Write the definition of the default constructor of YClass so that the
instance variables of YClass are initialized to 0 .
b. Write the definition of the default constructor of XClass so that the
instance variables of XClass are initialized to 0 .
c. Write the definition of the method two of YClass so that the instance
variable a is initialized to the value of the first parameter of two and the
instance variable b is initialized to the value of the second parameter of two .
12. Suppose that class Three is derived from class Two and class Two is
derived from class One and each class has instance variables. Suppose
that an object of class Three enters its scope, so the constructors of these
classes will execute. Determine the order in which the constructors of these
class es will execute.
13. What is the difference between overloading a method name and overriding
a method name?
14. Name two situations in which you would use the reserved word super .
15.
1
0
Suppose that the class GradStudent is derived from the class Student
and the class Student has the following method:
public void printGrades()
Search WWH ::




Custom Search