Win a copy of Functional Reactive Programming this week in the Other Languages forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Inheritance

 
paramasivam Ramu
Ranch Hand
Posts: 39
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 18671
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Raghu Shree
Ranch Hand
Posts: 143
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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..
 
paramasivam Ramu
Ranch Hand
Posts: 39
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi are you on line
 
Boenyamien Manuel
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 195
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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

 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic