This week's giveaway is in the Android forum.
We're giving away four copies of Android Security Essentials Live Lessons and have Godfrey Nolan on-line!
See this thread for details.
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 Android Security Essentials Live Lessons this week in the Android forum!
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
 
Similar Threads
javax.naming .NameNotFoundException:
Printing a primitive array
Downcasting allowed or not ???
Set.toArray
UnInitialized Strings