Showing posts with label OOP. Show all posts
Showing posts with label OOP. Show all posts

Saturday, May 12, 2012

What is an instance?

An instance is created from a class. The class can be seen as a blueprint and the instance is the actual object that is created from the blueprint. The class can make several objects or instances with different attributes. A Car Class would be able to have different instances for example, such as BMW, Honda, Jaguar, Mercedes.

In my own words,

an instance is a particular case in which an object is created from a set of defined attributes and functions from a blueprint or class.

Friday, May 11, 2012

What is a class?

A class is a blueprint or a model on which individual objects or instances can be created. A class will contain variables, methods that describe its behaviours. A class usually represents a blueprint of a real-life object that needs to be represented.

Example: The car Honda can be an instance of a Car class. It will have its own set of properties includign the color, model, design, number of doors etc. The instance, Honda, will have different properties than another instance of the car class, Ferrari for example.

12/5/12 Edit:

A class is a blueprint that contains attributes and functions that will be used to create instances as a representation of something.

Monday, February 13, 2012

What is a Class?

While going to work today, I was reading up on some java questions that interviewers like to ask. The first question, What is a class?, caught me off guard as it has been a long time since I had to formally define what a class is. I figure that the best way for me to re learn all of this is to answer the questions using my own definitions and words.

What is a class?
Looking at the Head First Java Book, I came upon definitions and examples of what is in a class, but not exactly what a class is in terms of object oriented programming. "A class has one or more methods" is an explanation of what goes into a class but not necessarily the definition that I think would serve me well.

Going to the Java online web pages, I found a definition stating that a class can be used to create "an instance of the class of objects". What I would take away from this definition is that a class be considered a blueprint that can be used to make "copies" or instances.

An app that I read said that a class is a "template for a set of objects that share a common structure and common behavior".

I like that definition and I think by summing up all the definitions above, I can produce my own definition that would always be ingrained in my mind, as I took time to find and read several definitions before summing it up on my own words.

What is a class?
A class is a blueprint that is used to create objects or instances that  are similar in structure and common behavior. An example of a class is the Car class. All cars would have wheels, doors, windows and hence these attributes can be defined in the class as variables. The number of doors and windows might be different for each "instance" or "type" of car manufactured.

I like creating a post about OOP concepts every now and again to refresh my memory. That's all for now :D