Get your CodeRanch badge!*
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes Import Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "Import" Watch "Import" New topic
Author

Import

Glen Iris
Ranch Hand

Joined: Jul 13, 2011
Posts: 164

Question 62 Quiz C S&B Ebook

Given the directory structure:

org
|--Robot.class
|
|--ex
......|--Pet.class
......|
......|--why
...........|--Dog.class

And the following source file:

class MyClass{
Robot r;
Pet p;
Dog d;
}

Which statements must be added for the source code to compile:

A- package org;
B- import org.*;
C- package org.*;
D- package org.ex;
E- import org.ex.*;
F- package org.ex.why;
G- package org.ex.why.Dog;


The correct answers are B,E and F.

So what I would like to know is:

1 - When we say "import org.*;" does this only import the files in the org directory and not any subdirectories?


OCPJP 6, OCMJD
Govindarajan Gowrisankaran
Greenhorn

Joined: Jan 16, 2012
Posts: 4
Yes when you import org.* only files in the org directory will be imported in to your source file and no files will be imported from the subdirectory of org.
Glen Iris
Ranch Hand

Joined: Jul 13, 2011
Posts: 164

Thank you Govindarajan Gowrisankaran .

With regard to this question, how are you supposed to know/deduce what directory MyClass is in?
Govindarajan Gowrisankaran
Greenhorn

Joined: Jan 16, 2012
Posts: 4
There is no necessity to know where your MyClass has been placed. You are just creating instances of Pet, Dog and Robot classes which are in different directories and inorder to create objects you should use import statements to let the compiler know where your class files has been placed.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Import
 
Similar Threads
Package
Import and package Issue
right way to peek inside others house.....:-)
Accessing Class
protected doubt