File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes inheritence Big Moose Saloon
  Search | Java FAQ | Recent Topics
Register / Login


Win a copy of The Mikado Method this week in the Agile and other Processes forum!
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Reply Bookmark "inheritence" Watch "inheritence" New topic
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
 
I agree. Here's the link: http://zeroturnaround.com/jrebel - it saves me about five hours per week
 
subject: inheritence
 
Similar Threads
join and in
instanceof question?
FileWriter
Question about document ready block
Implementing an Interface Down the Inheritance Tree Question