• 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

see this code

 
Greenhorn
Posts: 7
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
class A
{
some methods()
}
class B extends class B
{
Some methods
}
class c extends class B
{
public static void main(String a[])
{

A a=new C();
// what is use of reffering like this if we cant access the methods in class C by a refferrin variable
}
}
 
Ranch Hand
Posts: 490
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Strictly speaking, that is not true. You can access overridden methods(from A and B) in class C, and from those you can access methods in C, that are not overridden.

Using base class references to derived class objects can be very powerful, although it tends to be overused by people who think it is always the best way. It is a very useful feature in things like design patterns, not something you need to know now, but keep it in the back of your mind, when you are ready. Basically, it gives a way to keep code loosely coupled and easil to modify.

For now, just understand how it works and what pitfalls exist like trying to call a method in C that is not defined in a parent, or trying to use a derived class reference to a base class object. When you go deeper into OO concepts it will make sense.
[ March 29, 2006: Message edited by: Rusty Shackleford ]
 
Don't get me started about those stupid light bulbs.
reply
    Bookmark Topic Watch Topic
  • New Topic