Mega Code Archive

 
Categories / Java Tutorial / Class Definition
 

Storing a reference to the String object as type Object

A variable of type Object can store a reference to an object of any class type. public class MainClass {   public static void main(String[] a) {     String saying = "A stitch in time saves nine.";     Object str = saying;     System.out.println(str);     System.out.println(str.getClass().getName());   } } A stitch in time saves nine. java.lang.String