Questions About Object Superclasses and Casting

I am preparing a Java exam. I came across the following question

String s = new String ("hello");
Object o = (object) s;

Since oand sare the links pointing to the same object, if there is a difference in access to the object via a link son the link o?

I would be right to say that all objects (such as references to s) are subclasses Objectin Java and as such, using a link s, you can call methods known to the superclass Objectas well as clone()methods known Stringas length(). While a reference to an object of a superclass ocan only call its own methods, not subclasses? Thank.

+3
source share
1 answer

, o , String.

, o, String, . , o.toString() "", , Object.toString(). .

+1

All Articles