We help IT Professionals succeed at work.

Check out our new AWS podcast with Certified Expert, Phil Phillips! Listen to "How to Execute a Seamless AWS Migration" on EE or on your favorite podcast platform. Listen Now

x

Difference between Objects, Classes, Instances, Methods

jolyjf
jolyjf asked
on
Medium Priority
335 Views
Last Modified: 2013-11-23
For todays I tried to figure out what was the difference between objects, classes, instances and methods! It is so confusing! I've read a dozen tutorials and haven't understand this properly yet! Take the following for ex:

public class HelloWorld extends Applet {    
  public void paint(Graphics g) {
    g.drawString("Hello world!", 50, 25);    
  }
}

Now I would think that "HelloWorld" is a class. That seems pretty obvious. "paint" I think is a method. Am I right? So in this exemple there aren't any objects and instances? (whatever they are)

I'm really confused... your help would be really appreciated! Thank you very much!

Jean-Francois Joly
jolyal@capitalnet.com
Comment
Watch Question

Commented:
Unlock this solution and get a sample of our free trial.
(No credit card required)
UNLOCK SOLUTION

Commented:
jolyjf, I'll also give it a try to help from a different angle and I hope this wouldn't confuse you.
As msmolyak said, Object is a generic Object Oriented programming term. Let use a traditional example. Say you want to represent
an object. This object is a cat. A cat have a definition, certain behaviors and there are many cats living in the word. So, the class - the definition of the cat can be (not in a specific language) "A four legged animal that can eat and walk". This definition can define most of the living animals. Now, the cat I define have several ways of behavior. I define them by "hungry", "afraid", "happy". These will be methods that will define the objects behavior under different stimulus. Now, I have three cats at home, and the definition is written on the paper. I need 'live' cats. The instantiation of the definition - the creation of a live copy of the definition, is the instance. I have three instances of a "A four legged animal that can eat and walk", that walk after me when hungry, run when afraid, and purr when happy.
Did that made any sense?

Commented:
I totally agree. Try to read some introductory book in 'Java Programming'. There usually is a Chapter dedicated on Object Oriented approach in programming (which some people reasonably call Method Oriented).

Apart from the objects, instances, and classes, there many other interesting things, for example, concerning the members of the class definition - data members, operations (methods). Some keywords are: OOP, virtual mehtods, single(/multiple - not in java except interfaces) inheritance, interfaces, threads, and many others.

Wait,..., I'm accessing the university library now, let me see an appropriate book in Java...
"Java programming language handbook / Anthony Potts, David H. Friedel Jr.. - Scottsdale, AZ : Coriolis Group Books, cop. 1996. - XVII, 414 p. : ill. ; 24 cm. - (Internet programming series)
ISBN 1-88357-777-2"
This I find appropriate.

Success.

Commented:
Hi,

I'll give your question a shot...

The way I see it, a Class in an abstraction, while an Object is concrete.  A Class is a "type", like int & float are types, while objects are concrete instances of these types.

For example:
  int x, y;
  float a, b;

Here the abstract data types are int & float, i.e. int & float are the Classes.  They do not exist in any sense of reality.  They merely define what integers and floats look like.  On the other hand 'x' & 'y' are Objects of type (or Class) "int".  They exist in memory, and have a certain set of properties that are defined in Class int.

OO languages like Java & C++ allow you to define your own types or Classes.

For Example:

/*---------------Define a Class------------------------------- */
class Car
{
//define properties of a car, eg. wheels, steering wheel,engine, etc
//define the behavior of a car, ie. what a car can do.  This are programmatically represented as "Methods".
}

/*---------------"Instantiate" the Class---------------------- */
public static void main (String[] args)
{
  Car MyCar, YourCar, HisCar, HerCar; //process of Instantiation
}

Here "MyCar", "YourCar", "HisCar", & "HerCar" are instances of the Class "Car".

I am not sure if that has helped at all, but I hope it has :)

Cheers,
AviP

Commented:
A minor comment: int and float are not really abstract data types. They are so-called built-in data types and they make Java "not purely OO language" (I do not think they are a deficiency of the language). Thus variables of those types are not really objects, they are simply values.
Unlock the solution to this question.
Thanks for using Experts Exchange.

Please provide your email to receive a sample view!

*This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.

OR

Please enter a first name

Please enter a last name

8+ characters (letters, numbers, and a symbol)

By clicking, you agree to the Terms of Use and Privacy Policy.