aspose file tools*
The moose likes Beginning Java and the fly likes Object data Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Object data" Watch "Object data" New topic
Author

Object data

jacob deiter
Ranch Hand

Joined: Apr 02, 2008
Posts: 576
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

Joined: Mar 07, 2007
Posts: 1280

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
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Object data