1

i m jst confused that which of the two exists in the memory a class or the object?

4
  • 3
    Which is moving? The flag, or the wind? Commented Nov 26, 2009 at 14:23
  • 2
    which language are you asking about? Java or Javascript? Commented Nov 26, 2009 at 14:24
  • Javascript does not have classes. The only answer to this question is "mu". Commented Nov 26, 2009 at 15:08
  • What language are you talking in? m? jst? Commented Nov 26, 2009 at 16:01

2 Answers 2

3

The object.

At some extent, the class too, but I think what you mean is to clarify which one is the one holding the data.

For instance:

This is the class:

class Employee {
    String name;
}

And instance object would be:

Employee e = new Employee();
e.name = "himangi";

Employee other = new Employee();
other.name = "John";

There you have two objects, e and other they do exist in memory.

What makes it a little confuse is that Java stored the class definition as an object too, so in runtime you can have a the class object that represent the Employee class.

 Class employeeClass = Employee.class;
 System.out.println( employeeClass.getName() );

But then again, what exist in memory is the object.

Sign up to request clarification or add additional context in comments.

Comments

1

The class is the blueprint for the object.

The class defines the methods and properties that an object will support / use.

The object is an instance of the blueprint.

Every time you create an object it will be held in memory,

i.e. 10 objects = 10 memory stored instances

A class is stored in memory so that the runtime environment can "lookup" the class definition / blueprint and create a new instance for you.

The difference here is that only one definition of the class would be stored in memory, regardless of the number of objects you create.

1 Class definition can have many object instances (unless the class is marked as static in which case there is 1 class definition and 1 instance.).

The same is true for most compiled languages.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.