This week's book giveaway is in the Servlets forum.
We're giving away four copies of Murach's Java Servlets and JSP and have Joel Murach on-line!
See this thread for details.
The moose likes Beginning Java and the fly likes see this code Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "see this code" Watch "see this code" New topic
Author

see this code

anilkumar vankayalapati
Greenhorn

Joined: Mar 22, 2006
Posts: 7
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
}
}
Rusty Shackleford
Ranch Hand

Joined: Jan 03, 2006
Posts: 490
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 ]

"Computer science is no more about computers than astronomy is about telescopes" - Edsger Dijkstra
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: see this code
 
Similar Threads
design pattern
Method invoking
Javaranch Tips/Tricks question
Does is-a imply has-a ?
Is this a design pattern?