Skip to main content

Newbie help wanted

2 replies [Last post]
Joined: 2010-03-02

I am in the process of teaching myself Java. I am using both the Sun web-site tutorials and what my job offers. I have a question, what is the difference between an Object and a Class? I looked on Wikianswers but unfortunately I don't understand their answer (at this point like reading Greek).

I know a class contains variables and methods, so is an object the same thing?

I know this forum is for advanced people / professions who already have masterd this stuff so bear with me.

Reply viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.
Joined: 2010-03-29


I am also teaching myself Java and I will be glad to help whenever you migth need it.
To answer your post , a class is like a template or blueprint if you prefer that enables you to create many objects that have the same attributes and behaviour but with different state.

An example :

//here you have a class student

public class Student {
String name;
int age;

public Student(String theName,int theAge) {

public void setName (String newName) {


//here i create student objects

Student student1= new Student("John",20);
Student student2= new Student("Marie",30);

Both are objects created from the Student class; they have the same attributes name and age; the same behavior since can do the same thing with the setName method ; but they have different states since the value of the attributes differ.

Hope this was helpful

Joined: 2007-11-23

For example this is a class:

class Dog
int age;
String color;
String name;
public void run(){


An object Dog is an instance of that class. The class Dog helps you to create many objects.

Dog fifi=new Dog();
fifi.color = "yellow"; = "fifi";

Dog marvella=new Dog();
marvella.color = "yellow"; = "fifi";

In summary in this example we have one Class called Dog, and two objects of that class: fifi and marvella.