| Author |
inheritence
|
Sumi Festus
Greenhorn
Joined: Feb 04, 2005
Posts: 14
|
|
Hi.. Consider two public classes test1,test2 in different packages..test1 is imported in test2 and test2 also extends the class test1.. Is this legal..
|
 |
Mike Gershman
Ranch Hand
Joined: Mar 13, 2004
Posts: 1272
|
|
That will work if test1 has public access and the members and constructors of test1 referenced within test2 have public or protected access. [ February 04, 2005: Message edited by: Mike Gershman ]
|
Mike Gershman
SCJP 1.4, SCWCD in process
|
 |
ankur rathi
Ranch Hand
Joined: Oct 11, 2004
Posts: 3829
|
|
|
Sumi , what you are saying is correct . But Mike you are confusing me ...
|
 |
shandilya popuru
Ranch Hand
Joined: Dec 21, 2004
Posts: 95
|
|
|
what mikes saying is that u cannot access a class which is in a diffrent package and has a package level access
|
sandy
|
 |
Subhash Bhushan C
Ranch Hand
Joined: Jan 27, 2005
Posts: 106
|
|
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...
|
Regards,<br />Subhash Bhushan.
|
 |
Sumi Festus
Greenhorn
Joined: Feb 04, 2005
Posts: 14
|
|
Thanks a lot guys i really understood inheritence... Thank u
|
 |
 |
|
|
subject: inheritence
|
|
|