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


No comments:

Post a Comment