Skip to content
GK24
GK NotesComputer AwarenessObject-Oriented Programming Concepts

Object-Oriented Programming: Classes, Objects and Pillars

Complete notes on object-oriented programming concepts for exams: class and object, the four pillars, constructors, inheritance types and languages with their developers.

By · Published · 5 min read

Object-Oriented Programming: Classes, Objects and Pillars — GK24 title card
Object-Oriented Programming: Classes, Objects and Pillars — GK24 title card

Object-oriented programming, usually shortened to OOP, is a way of writing software in which the program is built out of objects that hold both data and the operations on that data, instead of a long list of instructions acting on separate variables. The approach became the standard for large software because it keeps related things together and lets code be reused. In competitive exams the topic is almost entirely definitional: a question gives you a one-line description and asks for the feature, or gives a feature and asks for the language or its developer. Learning the four pillars with one example each, and the small table of languages and their creators, is enough to answer nearly every question asked from this chapter.

From procedural to object-oriented programming

In procedural programming, as in C, FORTRAN or COBOL, a problem is broken into functions and the data is passed between them, so any function can change any global variable. In object-oriented programming the problem is broken into objects; the data of an object is normally kept private and can be changed only by the methods of that object. The result is less accidental damage to data, easier maintenance of large programs and simpler reuse. Procedural code is said to be function-centred and object-oriented code data-centred, a contrast examiners state in exactly those words.

Class and object: the basic pair

A class is a blueprint or template that defines what data members and member functions its members will have; writing a class does not by itself reserve memory for data members. An object is an instance of a class, created from that blueprint, and it occupies memory. Student may be a class, while Rahul and Meena are objects of it. The variables inside are called data members or attributes and the functions are called member functions or methods. One class can have any number of objects. When one object calls the method of another, the older textbooks call it message passing.

The four pillars of OOP

FeatureWhat it meansEveryday example
EncapsulationWrapping data and the methods that work on it into a single unit, the class, and keeping the data privateA capsule holding the medicine; a bank account whose balance can change only through deposit and withdraw methods
AbstractionShowing only the essential features to the user and hiding the internal implementationA car accelerator: you press it without knowing the engine design
InheritanceA new class acquiring the properties and behaviour of an existing class, which allows reuseCar and Bus inheriting from the class Vehicle
PolymorphismThe same name behaving differently in different situations, from the Greek for many formsOne method name area used for a circle and a rectangle

Many textbooks add two more ideas to this list, data hiding and modularity, but when a paper asks for the basic features of OOP the expected answer is the four above.

The terms that carry marks

  • Constructor: a special member function with the same name as the class that is called automatically when an object is created, usually to initialise it. It returns no value, not even void.
  • Destructor: the member function called automatically when an object is destroyed, written with a tilde before the class name in C++.
  • Function overloading: several functions with the same name but different parameter lists in the same class. It is resolved by the compiler, so it is called compile-time or static polymorphism.
  • Function overriding: a derived class redefining a method of its base class. It is resolved while the program runs, so it is called run-time or dynamic polymorphism, achieved in C++ through virtual functions.
  • Access specifiers: private members are available only inside the class, protected members also inside derived classes, and public members anywhere. Private is the default in a C++ class.
  • Abstract class: a class that cannot be instantiated and exists to be inherited; in C++ it is a class with at least one pure virtual function, and in Java an interface serves a similar purpose.

Types of inheritance

Single inheritance has one base and one derived class. Multiple inheritance gives one derived class two or more base classes. Multilevel inheritance forms a chain, A to B to C. Hierarchical inheritance gives one base class several derived classes. Hybrid inheritance combines these forms. The class that is inherited from is the base, parent or super class, and the new one is the derived, child or sub class. C++ supports multiple inheritance, Java does not support it with classes and achieves the same effect with interfaces, a difference papers like to test.

Languages and their creators

LanguageDeveloperNote
Simula 67Ole-Johan Dahl and Kristen NygaardRegarded as the first object-oriented language; introduced classes and objects
SmalltalkAlan Kay and his team at Xerox PARCAlan Kay coined the term object-oriented programming; a purely object-oriented language
C++Bjarne Stroustrup, Bell LaboratoriesBegan as C with Classes and was named C++ in 1983; supports both procedural and object-oriented styles
JavaJames Gosling, Sun MicrosystemsReleased in 1995, first called Oak; platform independent through the Java Virtual Machine
PythonGuido van RossumReleased in 1991; supports object-oriented and other styles
C sharpMicrosoftDeveloped for the dot NET platform; object-oriented from the start

Why OOP is preferred, and its cost

Objects can be reused in other programs, data is protected from accidental change, teams can work on separate classes at the same time, and a change inside a class does not disturb the rest of the program as long as its interface stays the same. The price is that object-oriented programs are usually larger, need more design work before coding, and can run a little slower than tight procedural code. Languages such as C++ and Python that allow both styles are called hybrid or multi-paradigm languages, while Smalltalk is held up as a pure object-oriented language.

Exam Point of View

Papers ask three things from this chapter. First, definition to term: data plus functions in one unit is encapsulation, hiding implementation is abstraction, reuse is inheritance, many forms is polymorphism. Second, language to developer: Simula with Dahl and Nygaard, Smalltalk with Alan Kay, C++ with Bjarne Stroustrup, Java with James Gosling, Python with Guido van Rossum. Third, the fine distinctions: overloading against overriding, class against object, private against protected, and the fact that Java does not allow multiple inheritance through classes. Questions are single-statement and need no coding.

Important Facts

First OOP languageSimula 67, by Ole-Johan Dahl and Kristen Nygaard
Term coined byAlan Kay, who led Smalltalk at Xerox PARC
Four pillarsEncapsulation, abstraction, inheritance, polymorphism
C++Bjarne Stroustrup, Bell Laboratories; named C++ in 1983
JavaJames Gosling, Sun Microsystems; released 1995, first called Oak
PythonGuido van Rossum, released in 1991
ConstructorSame name as the class, called on object creation, returns no value
Compile-time polymorphismFunction and operator overloading
Run-time polymorphismFunction overriding, through virtual functions in C++
Types of inheritanceSingle, multiple, multilevel, hierarchical, hybrid
Default access in a C++ classPrivate

Practice MCQs on this topic

Q3.Computer AwarenessEasy

Wrapping up of data and the functions that operate on that data into a single unit is called

  1. A.Inheritance
  2. B.Encapsulation
  3. C.Overloading
  4. D.Compilation
Show answer
Correct answer: B. Encapsulation

Encapsulation means binding the data members and the member functions that act on them inside one unit, the class, and keeping the data private so that it can be reached only through the methods provided; the standard illustration is a capsule holding the medicine inside it.

Read the full explanation →
Q4.Computer AwarenessMedium

Showing only the essential features of an object to the user while hiding its internal details is known as

  1. A.Abstraction
  2. B.Encapsulation
  3. C.Inheritance
  4. D.Instantiation
Show answer
Correct answer: A. Abstraction

Abstraction presents only what the user needs, such as the accelerator and brake of a car, and keeps the internal working out of sight; in C++ it is obtained through abstract classes with pure virtual functions and in Java through interfaces and abstract classes.

Read the full explanation →
Q5.Computer AwarenessEasy

Who developed the C++ programming language?

  1. A.Dennis Ritchie
  2. B.James Gosling
  3. C.Bjarne Stroustrup
  4. D.Guido van Rossum
Show answer
Correct answer: C. Bjarne Stroustrup

Bjarne Stroustrup developed the language at Bell Laboratories, starting it as C with Classes and giving it the name C++ in 1983; it adds classes, inheritance and polymorphism to C while keeping C procedural power, which is why it is called a hybrid language.

Read the full explanation →
Q7.Computer AwarenessMedium

In object-oriented programming, the ability of the same function name to work with different sets of parameters is called

  1. A.Inheritance
  2. B.Encapsulation
  3. C.Function overloading
  4. D.Function overriding
Show answer
Correct answer: C. Function overloading

Overloading means defining several functions of the same name in the same class with different numbers or types of parameters, so the compiler decides which one to call; because the decision is taken before the program runs, it is called compile-time or static polymorphism.

Read the full explanation →
Q8.Computer AwarenessEasy

Which statement about a class and an object is correct?

  1. A.A class is an instance of an object
  2. B.An object is a blueprint and a class is its instance
  3. C.A class is a blueprint and an object is its instance
  4. D.A class and an object both occupy memory in the same way
Show answer
Correct answer: C. A class is a blueprint and an object is its instance

A class only describes the data members and member functions that its objects will have, while an object is created from the class, occupies memory and holds actual values; one class may have any number of objects.

Read the full explanation →
Q12.Computer AwarenessMedium

In C++, members of a class declared as private can be accessed

  1. A.From anywhere in the program
  2. B.Only within the same class
  3. C.Within the class and its derived classes
  4. D.Only from the main function
Show answer
Correct answer: B. Only within the same class

Private is the most restricted access specifier and is also the default for a C++ class, so private data members can be read or changed only by the member functions of that class, and by a friend function or friend class if one is declared.

Read the full explanation →

Frequently Asked Questions

What are the four basic concepts of object-oriented programming?

Encapsulation, which binds data with the methods acting on it; abstraction, which hides implementation and shows only essentials; inheritance, which lets one class take the features of another; and polymorphism, one name behaving in many forms.

What is the difference between a class and an object?

A class is the blueprint or template that declares data members and member functions, and it does not reserve memory for data members. An object is an instance created from the class; it occupies memory and holds actual values.

What is the difference between function overloading and function overriding?

Overloading uses the same function name with different parameter lists in one class and is resolved by the compiler, so it is static polymorphism. Overriding redefines a base class method in a derived class with the same signature and is resolved while the program runs, so it is dynamic polymorphism.

Which was the first object-oriented programming language?

Simula 67, developed by Ole-Johan Dahl and Kristen Nygaard, which introduced classes, objects and inheritance. Smalltalk, developed under Alan Kay at Xerox PARC, is cited as the first purely object-oriented language.

Why is Java said not to support multiple inheritance?

Java does not let a class extend more than one class, because two base classes could supply a member of the same name and create ambiguity, the diamond problem. A class may implement several interfaces instead, so Java supports multiple inheritance of interfaces but not of classes.

Sources

  • Computer Science, Textbook for Class XII — NCERT
  • Informatics Practices, Textbook for Class XI — NCERT
  • Computer Science and Engineering model curriculum, object-oriented programming course outline — All India Council for Technical Education
View all