• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Liutauras Vilda
  • Campbell Ritchie
  • Tim Cooke
  • Bear Bibeault
  • Devaka Cooray
Sheriffs:
  • Jeanne Boyarsky
  • Knute Snortum
  • Junilu Lacar
Saloon Keepers:
  • Tim Moores
  • Ganesh Patekar
  • Stephan van Hulst
  • Pete Letkeman
  • Carey Brown
Bartenders:
  • Tim Holloway
  • Ron McLeod
  • Vijitha Kumara

Import  RSS feed

 
Ranch Hand
Posts: 175
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?

 
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: 175
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.
 
Consider Paul's rocket mass heater.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!