*
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes Inheritance Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "Inheritance" Watch "Inheritance" New topic
Author

Inheritance

paramasivam Ramu
Ranch Hand

Joined: Mar 30, 2005
Posts: 39
Read the code below,is it inheritance?.please explain me in realtime example.

college
cse ece mechanical
students,regno students,regno
Jim Yingst
Wanderer
Sheriff

Joined: Jan 30, 2000
Posts: 18671
Was there supposed to be some code somewhere?

And what's "regno"? I know it's a word in Italian, but not in English as far as I know. I can't tell how it's being used here.


"I'm not back." - Bill Harding, Twister
Raghu Shree
Ranch Hand

Joined: Mar 18, 2005
Posts: 143
Hi,
I think you want class structure of the given members. Am I correct? If yes check the below code

if any doubts reply me..


Raghu J<br />SCJP 1.4<br /> <br />The Wind and waters are always<br />on the side of the ablest navigators.<br /><a href="http://groups.yahoo.com/group/scjp_share" target="_blank" rel="nofollow">SCJP Group</a><br /><a href="http://groups.yahoo.com/group/JavaBeat_SCWCD" target="_blank" rel="nofollow">SCWCD Group</a>
paramasivam Ramu
Ranch Hand

Joined: Mar 30, 2005
Posts: 39
Raghu Shree,
My question is,is it necessary for an IS-A relationship to compulsarily exists in case of inheritance.
if possible plz explain with a real-time example.
regards,
-ramu
Boenyamien Manuel
Greenhorn

Joined: Apr 10, 2005
Posts: 2
Hi are you on line
Boenyamien Manuel
Greenhorn

Joined: Apr 10, 2005
Posts: 2
Hi Paramasivum Ramu.
I see that you are battling with Inheritance.
Here is the solution for the Mobile.java which you ask about.
I gave you a reply on the weekend and had the instantiation the wrong way round.
Here is your solution and I am not using static methods at all.
I gave three instantiations.
You can decide which instantiation to use to produce your desired output.
You can email me if you want further explanation on inheritance.

THE MOBILE.JAVA PROGRAM

class Vertibrate{

public void move(){
System.out.println("Move");

}
}

class Mammal extends Vertibrate{
public void move(){
super.move();
System.out.println("Walks");
}

}

class Dog extends Mammal {
public void move(){
super.move();
System.out.println("Walks on paws");
}

}

public class Mobile {

public static void main(String[] args){

Vertibrate Vertibrates = new Vertibrate();

Vertibrate Mammals = new Mammal();

Vertibrate Dogs = new Dog();


Vertibrates.move();

System.out.println("_____________________");

Mammals.move();
System.out.println("_____________________");

Dogs.move();
System.out.println("_____________________");



}
}
Joe Sondow
Ranch Hand

Joined: Apr 10, 2005
Posts: 195
Originally posted by paramasivam Ramu:
Raghu Shree,
My question is,is it necessary for an IS-A relationship to compulsarily exists in case of inheritance.
if possible plz explain with a real-time example.
regards,
-ramu


It isn't necessary but it is a very, very, very good idea to ensure that there exists an IS-A relationship between child and parent when using inheritance. I would not personally recommend the class structure Raghu Shree suggests, because it cannot logically be said that a department IS-A college, nor that a student IS-A department, nor that realTime IS-A student. A more traditional approach to that set of entities would say that a college HAS-A department, and that a department HAS-A student.

I'm not entirely clear on the example in the original posting, but it does not suggest inheritance to me. A simple example of inheritance might be something like this:

Vehicle
|
Car
|
BMW



SCJA 1.0 (98%), SCJP 1.4 (98%)
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Inheritance