Study guide

12.4 Inheritance, Polymorphism, and Overloading vs. Overriding

Praxis Computer Science 5652

Track your progress as you read

Finished sections get a check mark.

1 Chapter 1: Praxis 5652 Exam Overview and ETS Pseudocode

1.1 Praxis 5652 Test Facts, Scoring, and Registration 1.2 Official ETS Pseudocode Notation and Tracing Strategy

2 Chapter 2: Impacts of Computing: Innovation, Access, and Effects

2.1 Computing for Creativity, Problem Solving, Communication, and Innovation 2.2 Equal Access, the Digital Divide, and Accessibility 2.3 Beneficial and Harmful Effects of Computing Innovations

3 Chapter 3: Impacts of Computing: Intellectual Property, Ethics, Privacy, and Security

3.1 Intellectual Property: Copyright, Open Source, and Creative Commons 3.2 Ethical and Unethical Computing Practices and Their Implications 3.3 Privacy, Security, Data Collection, and Local vs. Cloud Storage

4 Chapter 4: Algorithms and Computational Thinking: Abstraction, Decomposition, Number Bases, and Representation

4.1 Abstraction and Abstraction Hierarchies 4.2 Decomposition, Pattern Recognition, and Developing Algorithms 4.3 Number Bases: Binary, Octal, Decimal, and Hexadecimal 4.4 Algorithm Formats: Natural Language, Flowcharts, Pseudocode, and Tracing

5 Chapter 5: Algorithms: Efficiency, Limits of Computing, and Randomization

5.1 Algorithm Efficiency: Linear, Quadratic, Exponential, and Logarithmic Growth 5.2 Limits of Computing: Unsolvable Problems, Intractability, and Heuristics 5.3 Randomization, Random vs. Pseudorandom Numbers, and Scaling to a Range

6 Chapter 6: Algorithms: Searching, Sorting, and Recursion

6.1 Searching Algorithms: Linear Search and Binary Search 6.2 Sorting Algorithms: Tracing, Comparisons, Correctness, and Efficiency 6.3 Recursion: Base Cases, Tracing, Errors, and Iterative Equivalents

7 Chapter 7: Programming: Variables, Data Types, Strings, and Expressions

7.1 Variables, Data Types, and Type Conversion 7.2 Strings and String Operations 7.3 Operators, Precedence, Expressions, and Formulas 7.4 Boolean Expressions, Truth Tables, and Boolean Algebra

8 Chapter 8: Programming: Selection, Iteration, and Writing Code

8.1 Sequence and Selection: if, else, Chained and Nested Conditions 8.2 Iteration: for, while, do … while, and repeat … until Loops 8.3 Reading, Completing, and Modifying Code

9 Chapter 9: Programming: Procedures, Arrays, and Data Structures

9.1 Procedures, Parameters, Return Values, Nested Calls, and Scope 9.2 Arrays, Lists, and Two-Dimensional Arrays 9.3 Stacks, Queues, and Dictionaries (Maps)

10 Chapter 10: Programming: Correctness, Errors, Testing, and Code Quality

10.1 Program Correctness: Preconditions, Postconditions, Invariants, and Testing vs. Proof 10.2 Error Types and Debugging Techniques 10.3 Choosing Useful Test Cases: Boundaries, Partitions, Coverage, and Regression 10.4 Extensibility, Modifiability, and Reusability: Constants and Parameterization 10.5 Documentation, Code Reviews, Peer Feedback, and End-User Feedback

11 Chapter 11: Programming: Events, Usability, Input Validation, and APIs

11.1 Event-Driven Programming, Asynchronous Events, and Concurrency 11.2 Usability, Meaningful Error Messages, and Input Validation vs. Verification 11.3 Libraries and APIs: Reading Definitions, Making Calls, and Weighing Trade-offs

12 Chapter 12: Programming: Languages, Tools, Paradigms, and Object-Oriented Design

12.1 Low- and High-Level Languages, Compilers and Interpreters, and IDEs 12.2 Programming Paradigms: Procedural, Object-Oriented, and Others 12.3 Classes, Objects, Instance Variables, Methods, and Encapsulation 12.4 Inheritance, Polymorphism, and Overloading vs. Overriding

13 Chapter 13: Data: Bits, Encoding, Compression, and Encryption

13.1 Bits and Bytes: Why Binary, Storage Calculations, and Signed Integers 13.2 Encoding Text, Images, and Sound 13.3 Lossless and Lossy Compression: Run-Length Encoding, Huffman Coding, and Media Formats 13.4 Encoding vs. Encryption, Symmetric and Public-Key Encryption, and Their Trade-offs

14 Chapter 14: Data: Analysis Tools, Simulation, Storage, and Collection

14.1 Analyzing Data with Spreadsheets: Cleaning, Transforming, and Visualizing 14.2 Simulation and Modeling 14.3 Files, Databases, and Storage Requirements: Scale, Redundancy, and Backup 14.4 Collecting, Aggregating, and Generating Data: Public Data Sets, Surveys, Sensors, and Crowdsourcing

15 Chapter 15: Computing Systems: Hardware, Operating Systems, and Computing Environments

15.1 Hardware Components and the Fetch–Decode–Execute Cycle 15.2 Operating Systems, Software Components, and Resource Issues 15.3 Embedded Systems, the Internet of Things, and Types of Computing Systems 15.4 Local, Network, and Cloud Computing and Storage; How Binary Data Are Stored

16 Chapter 16: Networks, the Internet, the Web, and Cybersecurity

16.1 Network Types and Wired and Wireless Communication 16.2 Network Hardware and Layered Network Models (OSI and TCP/IP) 16.3 Network Performance: Bandwidth, Latency, Load, and Estimating Needs 16.4 How the Internet Works: Protocols, IP Addressing, DNS, URLs, and Reliability 16.5 The Web: HTTP, HTML and Markup Languages, Browsers, Servers, and Clients 16.6 Cybersecurity: The Five Pillars, Strong Passwords, Security Strategies, and Trade-offs

12.4 Inheritance, Polymorphism, and Overloading vs. Overriding

Key Takeaways Explain This Topic AI

Inheritance models an "is-a" relationship: in ETS notation, class Dog extends Animal gives Dog all of Animal's public methods, which Dog can add to or override.

Benefits of inheritance include reusing code, organizing classes into hierarchies, extending a program by adding subclasses, and treating related objects uniformly through a superclass type.

Overriding: a subclass defines a method with the same name and parameter list as a superclass method, and the object's actual class determines which version runs.

Overloading: one class defines several methods with the same name but different numbers or types of parameters, and the arguments in a call determine which version runs.

Use inheritance for "is-a" relationships and composition (an object holding another as an instance variable) for "has-a" relationships.

Last updated: September 2026

What this competency asks

Under object-oriented programming concepts, ETS asks you to:

Identify the benefits of inheritance (and encapsulation, Section 12.3).

Identify distinctions between overloading and overriding.

The discussion question asks for an example of each and an explanation of the difference.

Inheritance

Inheritance lets a new class (the subclass , or child) be defined as an extension of an existing class (the superclass , or parent). In ETS notation the keyword is extends . class Animal

  • private String name
  • public String getName ( )
  • return name
  • end getName
  • public String speak ( )
  • return "..."
  • end speak
  • end class Animal
  • class Dog extends Animal
  • public String speak ( ) // overrides Animal's speak
  • return "Woof"
  • end speak
  • public void fetch ( ) // new behavior only dogs have
  • print "Fetching!"
  • end fetch
  • end class Dog

A Dog inherits getName without rewriting it, overrides speak , and adds fetch . Private superclass fields such as name are part of every Dog , but Dog 's own code reaches them only through inherited public (or protected) methods.

"Is-a" versus "has-a"

  • Relationship Test Design
  • Is-a "A Dog is an Animal." True Inheritance: Dog extends Animal

Has-a "A Car has an Engine." True; "a Car is an Engine" is false Composition : Car has an instance variable of type Engine

Using inheritance for a has-a relationship, such as making Car extends Engine , is a design error. It gives cars every engine method and misrepresents the model.

Benefits of inheritance

  • Benefit Example
  • Code reuse Shared fields and methods such as getName are written once, in the superclass
  • Organization Hierarchies mirror the domain: Shape → Circle, Rectangle
  • Extensibility Add a Triangle subclass without changing existing classes (Section 10.4)
  • Polymorphism Code written for Shape works for any subclass
  • Consistency A fix in the superclass applies to every subclass
  • Constructors and super

When a subclass object is created, the superclass part is initialized first , then the subclass's own part. In Java, a subclass constructor calls super ( … ) as its first statement to run the superclass constructor. The keyword super also lets an overriding method call the superclass version, as in super.speak ( ) .

Overriding and polymorphism

Overriding means a subclass provides its own version of an inherited method with the same name and the same parameter list . Which version runs is decided by the object's actual class when the program runs. This is dynamic dispatch , the core of polymorphism . Animal pet ← new Dog ( )

print pet.speak ( ) // prints Woof

The variable's declared type is Animal , but the object is a Dog , so Dog 's speak runs. A loop over a list of Animal references prints each animal's own sound. Adding a new subclass needs no change to the loop.

  • Polymorphism in a loop class Shape
  • public double area ( )
  • return 0.0
  • end area
  • end class Shape
  • class Rectangle extends Shape
  • private double width
  • private double height
  • public double area ( )
  • return width * height
  • end area
  • end class Rectangle
  • class Circle extends Shape
  • private double radius
  • public double area ( )
  • return 3.14 * radius * radius
  • end area
  • end class Circle
  • // constructors not shown: a 2 × 5 rectangle and a circle of radius 1
  • Shape[ ] shapes ← { new Rectangle ( 2, 5 ), new Circle ( 1 ) }
  • double total ← 0
  • for ( int i ← 0; i < 2; i ← i + 1 )
  • total ← total + shapes[i].area ( )
  • end for
  • print total

Trace: shapes[0] is a Rectangle , so its area returns 2 × 5 = 10. shapes[1] is a Circle , so its area returns 3.14 × 1 × 1 = 3.14. The program prints 13.14 . The loop never asks which kind of shape it holds. Each object answers with its own override, which is why a new Triangle extends Shape class can join the array without any change to the loop.

Abstract classes and interfaces

The area method in Shape returns a meaningless 0.0 only so that every shape has one. In Java, Shape would normally be declared abstract , with public abstract double area(); written without a body. An abstract class cannot be instantiated with new , and every concrete subclass must override its abstract methods. An interface goes one step further: it lists method headers that any implementing class promises to supply (modern Java interfaces may also include default methods with bodies). A Java class can extend only one class ( single inheritance ) but can implement many interfaces. Python and C++ allow a class to have several superclasses. ETS's pseudocode keyword list contains only extends , new , public , and private , so treat abstract and interface as Java vocabulary to recognize.

Overloading

Overloading means one class has several methods with the same name but different parameter lists (a different number, type, or order of parameters). The compiler chooses the version whose parameters match the call's arguments. class Geometry

  • public int area ( int side ) // square
  • return side * side
  • end area
  • public int area ( int width, int height ) // rectangle
  • return width * height
  • end area
  • end class Geometry

area ( 5 ) returns 25 and area ( 3, 4 ) returns 12. A different return type alone does not make a valid overload. The parameter lists must differ.

Overloading vs. overriding

  • Overloading Overriding
  • Where Usually within one class Subclass redefines a superclass method
  • Name Same Same
  • Parameter list Must differ Must be the same
  • Chosen by The arguments in the call (decided at compile time) The object's actual class (decided at run time)

Purpose Convenience: one name for related operations on different inputs Specialization: a subclass behaves in its own way

  • Example area ( int ) and area ( int, int ) Dog.speak ( ) replaces Animal.speak ( )
  • Worked example class Vehicle {
  • public void start() { System.out.print("V_start "); }
  • }
  • class Car extends Vehicle {
  • public void start() { System.out.print("C_start "); } // overrides
  • public void start(int keyId) { System.out.print("Key_" + keyId); } // overloads
  • }
  • Vehicle v = new Car();
  • v.start();

The output is C_start . v refers to a Car , and Car overrides the no-argument start , so dynamic dispatch picks Car 's version. The start(int) method is an overload : same name, different parameters. It is not called here.

Traps that separate the two

The declared type limits which methods can be called. After Animal pet ← new Dog ( ) , the call pet.fetch ( ) does not compile in Java, because the compiler checks the declared type Animal , and Animal has no fetch . The declared type decides which methods may be called . The actual object decides which override runs .

A changed parameter list turns an intended override into an overload. A Java Dog class that defines public boolean equals ( Dog other ) has not overridden the equals ( Object o ) method every class inherits from Object . It has overloaded it. Library code such as list.contains ( someDog ) calls equals with an Object parameter, so the new method is silently skipped. Writing @Override above a method asks the Java compiler to confirm that it really overrides something, which turns this mistake into a compile-time error.

Constructors are neither inherited nor overridden. Each class writes its own, and a subclass constructor reaches the superclass constructor through super ( … ) .

Python has no signature-based overloading. A second def area ( self, w, h ) in the same Python class simply replaces the first definition. Python code gets the same convenience from default parameter values, such as def area ( self, w, h = None ) . Overriding works in Python as it does in Java.