When imports are necessary

Post Reply
mattL

When imports are necessary

Post by mattL »

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

admin
Site Admin
Posts: 10036
Joined: Fri Sep 10, 2010 9:26 pm
Contact:

Re: When imports are necessary

Post by admin »

Hi Matt,
The question says "you have been given a library" and "makes use of the above library". These statements clearly indicate that you are not modifying the library but are only using it. Therefore, as per standard java development practices, your code would be in a different package than the library.

May be the question should make it more clear by saying "third party library" instead of just library.
If you like our products and services, please help us by posting your review here.

Post Reply

Who is online

Users browsing this forum: No registered users and 19 guests