Win a copy of Mesos in Action this week in the Cloud/Virtualizaton forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Object data

 
jacob deiter
Ranch Hand
Posts: 584
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
How the statement works

Object o=”stringvalue”

If I try the below I wont works

B b=new B();
B=”another value”;

 
Marco Ehrentreich
best scout
Bartender
Posts: 1294
IntelliJ IDE Java Scala
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Jacob,

because Object is the base class of all other classes in Java you can assign an instance of any class to a reference of type Object. Therefore you can of course assign the String object ”stringvalue” to it.

But as String is not a subclass of type "B" you obviously can't assign a String to a reference variable of type B.

Marco
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic