File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
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

Win a copy of Head First Android this week in the Android forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Object data" Watch "Object data" New topic

Object data

jacob deiter
Ranch Hand

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

Joined: Mar 07, 2007
Posts: 1294

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.

I agree. Here's the link:
subject: Object data
jQuery in Action, 3rd edition