Results 1 to 2 of 2

Thread: Object

  1. #1
    sireesha is offline Member
    Join Date
    Nov 2007
    Posts
    50
    Rep Power
    0

    Question Object

    Hi all,
    please see this code..
    Java Code:
    public class Box {
    
            private Object object;
    
            public void add(Object object) {
                this.object = object;
            }
    
            public Object get() {
                return object;
            }
        }
    In the above code what is the use of creating a object for Object class ?
    i saw creation of object for Object class in some other examples.
    what is the exact use of this ?
    thankq very much

  2. #2
    hardwired's Avatar
    hardwired is offline Senior Member
    Join Date
    Jul 2007
    Posts
    1,576
    Rep Power
    9

    Default

    Java Code:
    public class Test {
        public static void main(String[] args) {
            BoxRx box = new BoxRx();
            Object x = "x";
            box.add(x);
            Object whatIsIt = box.get();
            System.out.printf("whatIsIt = %s%nwhat class is it = %s%n",
                               whatIsIt, x.getClass().getName());
            box.add(75);
            whatIsIt = box.get();
            System.out.println("whatIsIt = " + whatIsIt);
        }
    }
    
    class BoxRx {
    
        private Object object;
    
        public void add(Object object) {
            this.object = object;
        }
    
        public Object get() {
            return object;
        }
    }

Similar Threads

  1. Replies: 2
    Last Post: 11-26-2010, 03:12 AM
  2. JSP - Application object example
    By Java Tip in forum Java Tip
    Replies: 0
    Last Post: 03-17-2008, 08:40 AM
  3. Object size
    By kavithas in forum New To Java
    Replies: 0
    Last Post: 11-30-2007, 01:00 PM
  4. Object ID
    By javaplus in forum New To Java
    Replies: 4
    Last Post: 11-26-2007, 01:08 PM
  5. Creating object of Type Object class
    By venkatv in forum New To Java
    Replies: 3
    Last Post: 07-17-2007, 04:33 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •