Java Reference
In-Depth Information
Exercise 9.14
In the same situation as before (class
Student
, no
toString
method), will
the following lines compile? Why?
Student st = new Student();
System.out.println(st);
Exercise 9.15
Assume that your class
Student
overrides
toString
so that it returns the
student's name. You now have a list of students. Will the following code compile? If not, why
not? If yes, what will it print? Explain in detail what happens.
for(Object st : myList) {
System.out.println(st);
}
Exercise 9.16
Write a few lines of code that result in a situation where a variable
x
has the
static type
T
and the dynamic type
D
.
Search WWH ::
Custom Search