OO Programming  «Prev 

Object-oriented Languages

You can write object-oriented code in almost any computer language, from low-level assembly to C to Perl.
Using a true object-oriented language makes OOP much easier, however, and more pleasant. Simula was the original object-oriented language (going as far back as 1967), but it is used rarely, if ever, these days.
Currently, the most popular object-oriented languages are C++, Java, and C#.


Smalltalk is perhaps the purest of the major object-oriented languages. It uses classes for absolutely everything, even primitive data types such as integers and floating-point numbers. It is extremely popular among a small group of developers and is well-regarded by the broader programming community.


C++ is the object-oriented language in most widespread use today. However, much of the time it is used as a "better C" rather than as a true object-oriented language. C++ can be very fast. It allows you to write object-oriented programs but it does not require you to.
Almost all C programs are also valid C++ programs, even though they do not have a single class or object. C++ has a rich feature set, which can make it both harder to learn and more powerful than other languages.


Java is the fastest-growing object-oriented language. Although it became famous for its ability to embed applets on Web pages, Java appeals to many programmers because it is a cleaner, purer object-oriented language than C++. Because Java does not attempt to maintain compatibility with C, it is able to get rid of a lot of things an object-oriented language does not need.


Even though there are a number of builtin reference types in JavaScript, you will most likely create your own objects fairly frequently. As you do so, keep in mind that objects in JavaScript are dynamic, meaning that they can change at any point during code execution. Whereas class-based languages lock down objects based on a class definition, JavaScript objects have no such restrictions.

Defining Properties

In JavaScript there are two basic ways to create your own objects:
  1. using the Object constructor and
  2. using an object literal.

For example:
var person1 = {
 name: "Glenn"
var person2 = new Object();
person2.name = "Glenn";
person1.age = "Redacted";
person2.age = "Redacted";
person1.name = "Greg";
person2.name = "Michael";