Results 1 to 6 of 6

Thread: object vs class

  1. #1
    billq is offline Member
    Join Date
    Dec 2009
    Posts
    25
    Rep Power
    0

    Default object vs class

    Hello, I am having difficulty with the difference between an object and a class. I thought an object is an instance of a class but the book I am reading gives me the impression they are 2 different things.
    thanks
    bill

  2. #2
    Fubarable's Avatar
    Fubarable is offline Moderator
    Join Date
    Jun 2008
    Posts
    19,315
    Blog Entries
    1
    Rep Power
    26

  3. #3
    raqman is offline Member
    Join Date
    Sep 2009
    Posts
    37
    Rep Power
    0

    Default

    A class is basically a definition, and contains the object's code. An object is an instance of a class. For instance, there is one java.lang.String class, but you can instantiate any number of distinct java.lang.String objects (instances). While a class defines the instance variables than an object has, the instantiated object itself actually contains those variables. So to put it simply: An object is an instance of a class.
    RAQ Report: free Java reporting tool.

  4. #4
    coltragon is offline Senior Member
    Join Date
    Dec 2009
    Posts
    104
    Rep Power
    0

    Default

    was confusing me too
    but i found a table and i was like this.

    Class Object

    Type Volvo
    ID 534-FGH

  5. #5
    JosAH's Avatar
    JosAH is offline Moderator
    Join Date
    Sep 2008
    Location
    Voorschoten, the Netherlands
    Posts
    13,784
    Blog Entries
    7
    Rep Power
    21

    Default

    Quote Originally Posted by billq View Post
    Hello, I am having difficulty with the difference between an object and a class. I thought an object is an instance of a class but the book I am reading gives me the impression they are 2 different things.
    thanks
    bill
    A class is a blueprint for an object of that class; all the objects 'know' their class and it's the class that stores the methods (both static and non-static) for each object (and the class itself in case of static methods). A class also declares the data members for the objects. A class also has its own data members (the static members). To add to the confusion you can also have objects that represent entire classes, the 'Class' object.

    kind regards,

    Jos

  6. #6
    billq is offline Member
    Join Date
    Dec 2009
    Posts
    25
    Rep Power
    0

    Default

    Thankyou for the replies. I am reading dave eck's book online. Sec 3.8 starts to talk about applets. And the sentence

    An applet is a Java program that runs on a Web page. An applet is not a stand-alone application, and it does not have a main() routine. In fact, an applet is an object rather than a class.

    confused me. I come from c++. And object is just an instance of a class. To me, the above sentence means that the applet is created from a class and not something else.

    thanks
    bill

Similar Threads

  1. geting object from other class
    By Mekonom in forum New To Java
    Replies: 10
    Last Post: 11-12-2009, 04:34 PM
  2. Passing SWT object to another class
    By Vinaya Lal Shrestha in forum SWT / JFace
    Replies: 0
    Last Post: 04-03-2009, 02:50 PM
  3. need help about java class and object
    By mrjohn007 in forum New To Java
    Replies: 1
    Last Post: 01-28-2009, 06:09 AM
  4. Getting name of object class
    By Java Tip in forum Java Tip
    Replies: 0
    Last Post: 11-05-2007, 06:22 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
  •