• 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
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

inheritence

 
Greenhorn
Posts: 14
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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..
 
Ranch Hand
Posts: 1272
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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 ]
 
Ranch Hand
Posts: 3852
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Sumi , what you are saying is correct . But Mike you are confusing me ...
 
Ranch Hand
Posts: 95
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
what mikes saying is that u cannot access a class which is in a diffrent package and has a package level access
 
Ranch Hand
Posts: 106
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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...
 
Sumi Festus
Greenhorn
Posts: 14
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks a lot guys i really understood inheritence...
Thank u
 
Consider Paul's rocket mass heater.
reply
    Bookmark Topic Watch Topic
  • New Topic