Object-Oriented Programming Foundations: Core Concepts, a Worked Trace and Exam Traps
Connect the main OOP ideas through one Shape hierarchy. Trace two runtime objects, method dispatch, exact area calculations and the traps that turn familiar terms into wrong answers.
KnowledgeGate Team
Exam prep & CS education

Class, object, encapsulation, abstraction, inheritance and polymorphism are easy to memorise as separate definitions. The difficulty begins when a base-class reference holds different derived objects and the same method call gives different results. Runtime dispatch selects the implementation that belongs to each actual object. OOP is an organisation model for state and behaviour, not merely syntax that uses classes.
What object-oriented programming organises
Object-oriented programming organises a program around collaborating objects that combine state with operations and interact through defined interfaces. An object has three useful aspects:
State, such as a circle's
radius=2.Behaviour, such as the circle's
area()operation.Identity, which keeps two separately created circles distinct even when both have radius 2.
This is organisation, not unique capability. Procedural code can calculate the same areas by passing records to circleArea(circle); OOP code can ask shape.area(). Neither is automatically faster, shorter or superior. The better model depends on whether its objects and responsibilities fit the problem.
Within Coding & Skills, OOP is one way to structure programming foundations. Object Oriented Technology Explained provides the wider map; the trace below concentrates on how the core ideas work together.
Classes, objects, state, methods and messages
A class describes its instances' permitted state and behaviour. An object is a runtime instance of that description. Here, Circle is a class, while C1 is one object with radius 2. A class is not a physical blueprint copied into every object, and an object is not merely a bag of fields. Its operations govern its state.
The example uses two objects. C1 is a Circle with private radius 2; F1 is a Frame with private outer dimensions 5 x 4 and inner opening 3 x 2. Both conform to abstract type Shape, which exposes label() and area(). Their states and algorithms differ, yet one Shape collection can hold both.
A method call requests an operation from a receiver. In current.area(), current identifies the receiver and area names the operation. Arguments would provide extra input; the returned number is the result. Languages need not implement calls identically internally.
The core OOP ideas and the boundary between them
Encapsulation groups state with the operations that maintain it behind a class boundary. In this model, radius and the frame's outer and inner dimensions are private. Constructor rules require positive dimensions and an opening smaller than the outer rectangle. Marking a field private is not enough if public methods can still place the object in an invalid state.
Abstraction selects the essential view offered to a client while suppressing unnecessary implementation detail. Shape.area() is the common promise. Its caller does not need to know whether the receiver multiplies (outerWidth * outerHeight) - (innerWidth * innerHeight) or calculates 3.1416 * radius * radius. Encapsulation creates and protects a boundary. Abstraction chooses what that boundary presents.
Inheritance expresses an is-a relationship in the model. Every Circle is a Shape, and every Frame is a Shape. It is not merely a mechanism for copying code. By contrast, Drawing has a list of Shape objects is composition, a has-a relationship.
Subtype polymorphism allows a variable declared as Shape to refer first to C1 and then to F1. The same area() request produces behaviour belonging to the runtime object. Overriding makes this possible here: each subtype supplies its implementation of the operation declared by Shape.
Worked example: build two objects and compute their total area

In this language-neutral pseudocode, abstract prevents direct construction of Shape, and concrete subclasses must implement area(). Only the owning class changes a private field. Pi is fixed at 3.1416; print2 rounds only the display to two decimal places.
abstract class Shape
private label
method label() = label
abstract method area()
class Circle inherits Shape
private radius
method area() = 3.1416 * radius * radius
class Frame inherits Shape
private outerWidth, outerHeight
private innerWidth, innerHeight
method area() = (outerWidth * outerHeight)
- (innerWidth * innerHeight)
shapes = [new Circle("C1", 2), new Frame("F1", 5, 4, 3, 2)]
total = 0
for each current in shapes
total = total + current.area()
print2(total)Before the loop, shapes[0] refers to C1, a runtime Circle with radius=2. shapes[1] refers to F1, a runtime Frame with outer dimensions 5 x 4 and an inner opening 3 x 2. Both satisfy the collection's advertised Shape interface.
Now trace every value without rounding early:
Start with
total = 0.For C1, runtime dispatch selects
Circle.area():3.1416 * 2 * 2 = 12.5664.Add the result:
0 + 12.5664 = 12.5664.For F1, runtime dispatch selects
Frame.area():(5 * 4) - (3 * 2) = 20 - 6 = 14.Add again:
12.5664 + 14 = 26.5664.print2(26.5664)displays26.57.
The unrounded circle area enters the addition. Early rounding is unsafe.
Follow the reference and runtime dispatch step by step

The loop makes one advertised request twice, while runtime dispatch selects each receiver's implementation.
Iteration | Declared reference type | Runtime object | Selected method | Total after call |
|---|---|---|---|---|
1 |
|
|
|
|
2 |
|
|
|
|
Keep two decisions separate. Declared type Shape determines which operations the pseudocode may request, so area() is allowed. The runtime class selects the overriding implementation. This is dynamic binding in this model, not a claim about every language.
If Shape did not declare area(), the loop could not request it through a Shape reference. Without an implementation, Frame would remain abstract and new Frame("F1", 5, 4, 3, 2) would be invalid. The correct trace is unchanged.
Traps that turn the right vocabulary into a wrong answer
Trap | Correction |
|---|---|
Class and object are interchangeable |
|
Equal state means identical objects | Two circles can both have radius 2 while retaining separate identities. |
Private fields guarantee encapsulation | Operations must preserve valid state too. |
Abstraction only hides information | Abstraction selects the essential view; encapsulation protects its boundary. |
Inheritance and composition mean the same thing |
|
Any function accepting different values is polymorphic | Here, one |
Do not merge overriding with overloading. Circle.area() overrides Shape.area() and is selected from the runtime object. area(scale) would instead be an overload distinguished by its parameter list under these rules.
Check numerical distractors precisely. 14 is only F1's area. 26.5664 is the unrounded total; 26.57 is its display. Rounding C1 to 12.57 early gives the same display by coincidence, but remains unsafe.
How exams test OOP foundations
Representative questions ask you to match class, object and method definitions, identify is-a and has-a relationships, separate encapsulation from abstraction, distinguish overloading from overriding, or trace a base-type reference that holds a subtype object. Output questions often require runtime dispatch and arithmetic together.
Apply exact checks. C1 is an object and Circle is its class. Circle is-a Shape, while Drawing has-a Shape collection. The first call selects Circle.area() and returns 12.5664; the second selects Frame.area() and returns 14; the unrounded total is 26.5664. The Programming Languages Survey places OOP beside other paradigms.
A distractor may use the frame's outer area of 20 without subtracting its opening, or may round the circle before addition. When a question names a programming language, apply that language's rules for access control, overriding and dispatch.
The short version and next step
Recall: class contract -> object state and identity -> encapsulated boundary -> abstract operation -> inheritance relationship -> overridden method -> runtime dispatch. C1 contributes 12.5664, F1 contributes 14, and the loop prints 26.57 after adding unrounded values.
Redraw the hierarchy and dispatch table without looking. Add a Square of side 3 and calculate its area before checking that it contributes 9, taking the unrounded total to 35.5664. Use the Java Programming Course to practise classes, objects and methods, or Zero to Hero for a broader CS route.
Keep learning
Object-Oriented Programming (OOPS): Core Concepts with a Worked C++ Example
Build one connected OOP model, then trace how two account objects respond differently through the same C++ base-class interface.
Object-Oriented Programming: Classes, Objects and Inheritance with a Worked Java Example
Trace two Java objects from construction to output, and see how independent state, inheritance and runtime method dispatch work together.
Object-Oriented Programming (OOP): Four Pillars and a Worked Dynamic-Binding Example
Build a precise OOP mental model, then follow two Employee objects through a Java program to see overloading, overriding and runtime dispatch in action.
Object Oriented Technology Explained: Four Pillars, Worked Java Examples, GATE and Interview Patterns
Build object oriented technology on one running Java example. Learn the four pillars, trace exact outputs, and separate overloading from overriding.





