Consider three classes : Vehicle, Car and TransportCompany
Packages :-
Vehicle - com.systemprovided - Public access
Car - com.myownpackage - Public access
TransportCompany - com.myownpackage - Public access
Let us assume class Vehicle has already been coded and given to us by a vendor.
Now, we want to build classes called Car and TransportCompany for a product, whose natures are indicated by their names.
Lets see. Car is a type of Vehicle. So when we code the Car class, we might as well use the features already provided by the Vehicle class and maybe, overload some methods so as to suit our own car class. Obviously, the relationship is "Car IS-A Vehicle". So, we import the Vehicle class into our Car class (we need to be able to see the class first, to access its members!!) and then we extend the Car class from it.
Again, a Transport company has lots of vehicles in its payroll. We are not saying the transport company has only cars... they may be trucks, buses etc. Essentially, the relationship is "TransportCompany HAS-A Vehicle" (one to many relationship). So, we import the Vehicle class into our TransportCompany class (again, we need to be able to see the class first, to use it in our own class) and then create instances of it in TransportCompany.
Hope its clear now... Now
you should be able to understand why its legal...