Java-Object Reference

Object Reference

Object is a superclass of all other classes. This means that a reference variable of type Object can refer to an object of any other class.


Program Source

class Data {
    int data1;

public class Javaapp {
    public static void main(String[] args) {
        Data dobj = new Data();
        dobj.data1 = 100;
        Object obj = dobj;
        System.out.println("obj equals dobj : "+obj.equals(dobj));
        Data dobj2 = (Data)obj;
        System.out.println("dobj2 data1     : "+dobj2.data1);

Leave a Comment