• Post Reply Bookmark Topic Watch Topic
  • New Topic

Object Reference Question  RSS feed

 
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
Ranch Hand
Posts: 7729
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Welcome to the Sun Certified Java Programmer Certification forum at JavaRanch.
I'm moving your question to our Java In General (Beginner) forum...
 
Ranch Hand
Posts: 2409
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
Ranch Hand
Posts: 97
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Is this some new Java syntax?



interesting....
 
Ranch Hand
Posts: 1249
Java Spring Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

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..
 
Java Cowboy
Sheriff
Posts: 16079
88
Android IntelliJ IDE Java Scala Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

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 ]
 
paul pavlentey
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

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..........
 
If you are using a wood chipper, you are doing it wrong. Even on this tiny ad:
The WEB SERVICES and JAX-RS Course
https://coderanch.com/t/690789/WEB-SERVICES-JAX-RS
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!