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 Object Reference Question 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 "Object Reference Question" Watch "Object Reference Question" New topic
Author

Object Reference Question

paul pavlentey
Greenhorn

Joined: Jul 20, 2006
Posts: 10
I have very basic Java Question about object assignment.
interface
+++++++++++++++++++++++++++++++++++++++++++++
public interface Animatable {
public void animate();
}
class
+++++++++++++++++++++++++++++++++++++++++++++
public class GameShape {
public void displayShape() {
System.out.println("Displaying Shape");
}

}
class which extends GameShape and implements interface Animatable
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
public class PlayerPiece extends GameShape implements Animatable{
public void movePiece() {
System.out.println("moving game piece");
}
public void animate() {
System.out.println("animating......");
}

}

I dont understand the following assignement of variable "player".
I understand new object player is created (
PlayerPiece player= new PlayerPiece() ,
but how player is assigned to Object, GameShape and Animatable.
Object o=player;
GameShape shape=player;
Animatable mover=player;

What will it to player and how instances of Object, GameShape and Anumatable are effected?

Thanks in advance,
Paul
Barry Gaunt
Ranch Hand

Joined: Aug 03, 2002
Posts: 7729
Welcome to the Sun Certified Java Programmer Certification forum at JavaRanch.
I'm moving your question to our Java In General (Beginner) forum...


Ask a Meaningful Question and HowToAskQuestionsOnJavaRanch
Getting someone to think and try something out is much more useful than just telling them the answer.
Keith Lynn
Ranch Hand

Joined: Feb 07, 2005
Posts: 2367
You can make the assignments because

Object o = player; - PlayerPiece "is a" Object

GameShape shape = player; - Player "is a" GameShape because PlayerPiece extends GameShape

Animatable mover = player; - Player "is a" Animatable because PlayerPiece implements Animatable
Douglas Chorpita
Ranch Hand

Joined: May 09, 2006
Posts: 97
Is this some new Java syntax?



interesting....


SCJP 1.4 - 95%
Shaan Shar
Ranch Hand

Joined: Dec 27, 2005
Posts: 1249

Originally posted by Douglas Chorpita:
Is this some new Java syntax?



interesting....



No this was the intresting postfix way for highlighting your code and comments.. I hope you understands well..


The Best way to predict your future is to create it - Every great individual common man
Jesper de Jong
Java Cowboy
Saloon Keeper

Joined: Aug 16, 2005
Posts: 14074
    
  16

Originally posted by Ankur Sharma:
No this was the intresting postfix way for highlighting your code and comments.. I hope you understands well..

For the original poster: We have the [ code ] ... [ /code] tags here in the forum to indicate a piece of source code. If you use them around the Java source that you post, the source code will be nicely formatted in your post.
[ July 21, 2006: Message edited by: Jesper Young ]

Java Beginners FAQ - JavaRanch SCJP FAQ - The Java Tutorial - Java SE 7 API documentation
Scala Notes - My blog about Scala
paul pavlentey
Greenhorn

Joined: Jul 20, 2006
Posts: 10
Originally posted by Jesper Young:

For the original poster: We have the [ code ] ... [ /code] tags here in the forum to indicate a piece of source code. If you use them around the Java source that you post, the source code will be nicely formatted in your post.

[ July 21, 2006: Message edited by: Jesper Young ]


Thank you I will post correctly next time..........
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Object Reference Question
 
Similar Threads
Polymorphism/Interface question
Object Reference Question
Oveririding confusion
Polymorphic method invocations
Regarding reference variable