• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Import

 
Glen Iris
Ranch Hand
Posts: 172
Chrome Java Netbeans IDE
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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?

 
Govindarajan Gowrisankaran
Greenhorn
Posts: 4
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 172
Chrome Java Netbeans IDE
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thank you Govindarajan Gowrisankaran .

With regard to this question, how are you supposed to know/deduce what directory MyClass is in?
 
Govindarajan Gowrisankaran
Greenhorn
Posts: 4
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic