Java Reference
In-Depth Information
{
System.out.println("SubClass: " + y);
super
.print();
}
public
SubClass()
{
super
();
y = 0;
}
public
SubClass(String s,
int
a,
int
b)
{
super
("Hello Super", a + b);
y = b;
}
}
What is the output of the following Java code?
SuperClass superObject =
new
SuperClass("This is superclass", 2);
SubClass subObject =
new
SubClass("DDDDDD", 3, 7);
superObject.print();
subObject.print();
Suppose that
class
Student
is derived from the
class
Person
, and the
class
es
UndergraduateStudent
and
GradStudent
are derived from the
class
Student
. (The
class
Person
is defined in Chapter 8.) Consider
the following method heading:
public void
printName(Student st)
{
21.
System.out.println(st.getFirstName() + " " + st.getLastName());
}
Suppose that
student1
is an object of the
class
UndergraduateStudent
and
student2
is an object of the
class
GradStudent
. Determine whether
the following statements are legal. Justify your answer.
printName(student1);
printName(student2);
22.
What does the operator
instanceof
do?
23.
What is an abstract method?
24.
What is the difference between an abstract class and an interface?
25.
Why does Java allow a class to implement more than one interface?
Search WWH ::
Custom Search