Forums Register Login

Import

+Pie Number of slices to send: Send
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?

1
+Pie Number of slices to send: Send
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.
+Pie Number of slices to send: Send
Thank you Govindarajan Gowrisankaran .

With regard to this question, how are you supposed to know/deduce what directory MyClass is in?
+Pie Number of slices to send: Send
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.
Where all the women are strong, all the men are good looking and all the tiny ads are above average:
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com


reply
reply
This thread has been viewed 838 times.
Similar Threads
Package
Import and package Issue
protected doubt
right way to peek inside others house.....:-)
Accessing Class
More...

All times above are in ranch (not your local) time.
The current ranch time is
Mar 28, 2024 03:04:06.