|
RHS |
Test 03
Name : ______________________________________________________
When answering the following questions be sure to read all introductions - they may include important declarations or information needed to solve the questions.
You should be able to answer all 27 questions (in 3 groups) in less then 30 mins.
Group 1
Check whether the following loops are valid.
If they are valid you should
also write down the output produced by the loop when it is executed.
Assume that the following declaration has been made: int j = 0;
Loop |
Valid |
Not valid Output |
||
| for (int i = 0, i < 5, i++)
|
||||
| for (i = 0; i < 5; i++)
|
||||
| for (int i = 0; i <= 5; i++)
|
||||
| for (int i = 0; i < 5; i++);
|
||||
| for (int i = 0; i < 5; i = i + 2)
|
||||
| while (j <= 5)
|
||||
| while (j < 5){
|
||||
| while (j < 5)
|
Group 2
Assume that the following two classes are fully implemented:
![]() |
Also assume the following declaration have been made: Person
pers = new Person("Peter", "HighStreet 12", "Roskilde");
Which of the following statements are valid?
Statement |
Valid |
Not valid |
||
| pers.toString();
|
||||
| Person.toString();
|
||||
| pers.getName();
|
||||
| String s = pers.getAddress();
|
||||
| String s = Person.getAddress();
|
||||
| Address a = pers.getAddress();
|
||||
| Address a = Person.getAddress();
|
||||
| String city = Person.getAddress.getCity();
|
||||
| String city = (Address) pers.getCity();
|
||||
| String city = pers.getAddress().getCity();
|
||||
| String city = pers.getAddress.getCity();
|
Group 3
Which of the following implementations of the toString() method
for the class Person would
be valid?
toString() |
Valid |
Not valid |
||
public String toString(){
|
||||
public String toString(){
|
||||
public String toString(){
|
||||
public String toString(){
|
||||
public String toString(){
|
||||
public String toString(){
|
||||
public String toString(){
|
||||
public String toString(){
|