• 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
  • Liutauras Vilda
  • Tim Cooke
  • Paul Clapham
  • Jeanne Boyarsky
Sheriffs:
  • Ron McLeod
  • Frank Carver
  • Junilu Lacar
Saloon Keepers:
  • Stephan van Hulst
  • Tim Moores
  • Tim Holloway
  • Al Hobbs
  • Carey Brown
Bartenders:
  • Piet Souris
  • Frits Walraven
  • fred rosenberger

about import statement

 
Ranch Hand
Posts: 188
IntelliJ IDE MySQL Database Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Question :
Given the following class

package org . myPack ;

public class Ques01 {

// some code

};

Which of the following are valid ways of refereing to the class from any other package besides org . myPack ?

Options :

a . Refer to the class as Ques01
b . Refer to the class as org . myPack . Ques01
c . Refer to the class as myPack . Ques01
d . import org . myPack . * & then refer to the class as Ques01
e . import org . * & then refer to the class as Ques01


according to me b & d are the rite ans

but according to the answer in the test i took b & e are the right answers

So please tell me if i am wrong ??
 
Ranch Hand
Posts: 30
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
interesting...

i think the answer should even include d ...
b,d and e...are my answers


Suresh Koutam
 
Ranch Hand
Posts: 377
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,

e is definitely wrong, since import doesn't work recursively.
 
Ranch Hand
Posts: 92
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Yes.option e is wrong.
In Collection to import all Collection classes and interfaces
we cannot say import java.*;This will give compile error.
We have to say import java.util.*;
 
Ranch Hand
Posts: 254
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
import does not import sub packages

Regards,
Joshua
 
Ranch Hand
Posts: 3389
Mac MySQL Database Tomcat Server
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thats right. Definitely option e is Wrong!!

As Manfred said, imports does not work recursively. You need to import the SPECIFIC Package!
 
You learn how to close your eyes and tell yourself "this just isn't really happening to me." Tiny ad:
Garden Master Course kickstarter
https://coderanch.com/t/754577/Garden-Master-kickstarter
reply
    Bookmark Topic Watch Topic
  • New Topic