• 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 Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Import

 
Ranch Hand
Posts: 176
Netbeans IDE Chrome Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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: 176
Netbeans IDE Chrome Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Don't get me started about those stupid light bulbs.
reply
    Bookmark Topic Watch Topic
  • New Topic