When imports are necessary
Posted: Thu Feb 24, 2011 7:50 pm
SCJA, Test 3, Question 40 reads as:
You have been given a library that contains the following class:
package com.cool;
public class Cooler {
public void doCool(){
System.out.println("cooling...");
}
}
Now, you are writing another class that makes use of the above library as follows:
// 1 insert code here
public class Furnace
{
public void cool(Cooler c) { // 2
c.doCool();
}
}
What should be inserted at //1 above?
I submit that one correct answer is:
"package com.cool;"
However this was graded as wrong. Nowhere in the question is it stated that the classes are in separate packages. Therefore putting Furnace in the same package as Cooler should result in a valid compilation. Plus, no imports are needed. What am I missing?
Thanks.
Matt
You have been given a library that contains the following class:
package com.cool;
public class Cooler {
public void doCool(){
System.out.println("cooling...");
}
}
Now, you are writing another class that makes use of the above library as follows:
// 1 insert code here
public class Furnace
{
public void cool(Cooler c) { // 2
c.doCool();
}
}
What should be inserted at //1 above?
I submit that one correct answer is:
"package com.cool;"
However this was graded as wrong. Nowhere in the question is it stated that the classes are in separate packages. Therefore putting Furnace in the same package as Cooler should result in a valid compilation. Plus, no imports are needed. What am I missing?
Thanks.
Matt