• Post Reply Bookmark Topic Watch Topic
  • New Topic

importing packages  RSS feed

 
Ranch Hand
Posts: 118
Android Java Objective C
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hi

While going through OCAJP 8 book. came across this para " Another case of redundancy involves importing a class that is in the same package as the class importing it" Now as per my understanding of this para goes... we trying to import a package say A which has got a class say Class1. Now we again try to import another class say Class2 from the same package A, this causes redundancy. Now if my assumption is right, what kind redundancy is caused. IF my assumption is wrong then what is the actual explanation of this para.


Thanks
 
Bartender
Posts: 2087
44
Firefox Browser IntelliJ IDE Java Linux Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You do not import packages. You import classes and interfaces.

Suppose you have a classYou want to use this class in another class:Now, importing A inside B would be redundant as both classes are in the same package.
 
krishnadhar Mellacheruvu
Ranch Hand
Posts: 118
Android Java Objective C
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hi

pawel,

Yup we do import classes and interfaces...

the import becomes redundant if we have allready created Class A object in Class B and then trying to import Class A explicitly in Class B.
 
Bartender
Posts: 689
17
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The import is redundant if both classes are in the same package. Classes can automatically access other classes that are in the same package without the need for an import (assuming the access modifiers permit that to happen).
 
krishnadhar Mellacheruvu
Ranch Hand
Posts: 118
Android Java Objective C
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi

mike,

So

Class A and Class B in package P. now in class B program if we are trying to import class A instead of accessing Class A via objects(pertaining to access modifiers),redundancy occurs.?
 
Mike. J. Thompson
Bartender
Posts: 689
17
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Yes, importing class A from class B is redundant if both classes are in the same package. It isn't an error though, it will still work.
 
krishnadhar Mellacheruvu
Ranch Hand
Posts: 118
Android Java Objective C
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks

Mike and Pawel for helping me in understanding this concept....
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!