Generalization, also known as Inheritance represents an "is-a" relationship between classes, where one class (the subclass or child) inherits the properties and behaviors of another class (the superclass or parent).
It shows how common attributes and behaviors can be defined in a base class and reused by derived classes. This reduces redundancy and promotes reusability in system design.
In UML class diagrams, generalization is depicted with a solid line and a hollow triangle pointing from the subclass to the superclass.
In the example of bank accounts, we can use generalization to represent different types of accounts such as current accounts, savings accounts, and credit accounts.
The Bank Account class serves as the generalized representation of all types of bank accounts, while the subclasses (Current Account, Savings Account, Credit Account) represent specialized versions that inherit and extend the functionality of the base class.

#include <iostream>
using namespace std;
// Generalization: Base class
class BankAccount {
public:
void accountType() {
cout << "This is a general bank account" << endl;
}
};
// Specialized classes
class SavingsAccount : public BankAccount {
public:
void accountType() {
cout << "This is a savings account" << endl;
}
};
class CurrentAccount : public BankAccount {
public:
void accountType() {
cout << "This is a current account" << endl;
}
};
class CreditAccount : public BankAccount {
public:
void accountType() {
cout << "This is a credit account" << endl;
}
};
int main() {
SavingsAccount s;
CurrentAccount c;
CreditAccount cr;
s.accountType();
c.accountType();
cr.accountType();
return 0;
}
// Generalization: Base class
class BankAccount {
void accountType() {
System.out.println("This is a general bank account");
}
}
// Specialized classes
class SavingsAccount extends BankAccount {
void accountType() {
System.out.println("This is a savings account");
}
}
class CurrentAccount extends BankAccount {
void accountType() {
System.out.println("This is a current account");
}
}
class CreditAccount extends BankAccount {
void accountType() {
System.out.println("This is a credit account");
}
}
public class Main {
public static void main(String[] args) {
SavingsAccount s = new SavingsAccount();
CurrentAccount c = new CurrentAccount();
CreditAccount cr = new CreditAccount();
s.accountType();
c.accountType();
cr.accountType();
}
}
# Generalization: Base class
class BankAccount:
def account_type(self):
print("This is a general bank account")
# Specialized classes
class SavingsAccount(BankAccount):
def account_type(self):
print("This is a savings account")
class CurrentAccount(BankAccount):
def account_type(self):
print("This is a current account")
class CreditAccount(BankAccount):
def account_type(self):
print("This is a credit account")
s = SavingsAccount()
c = CurrentAccount()
cr = CreditAccount()
s.account_type()
c.account_type()
cr.account_type()
// Generalization: Base class
class BankAccount {
accountType() {
console.log("This is a general bank account");
}
}
// Specialized classes
class SavingsAccount extends BankAccount {
accountType() {
console.log("This is a savings account");
}
}
class CurrentAccount extends BankAccount {
accountType() {
console.log("This is a current account");
}
}
class CreditAccount extends BankAccount {
accountType() {
console.log("This is a credit account");
}
}
const s = new SavingsAccount();
const c = new CurrentAccount();
const cr = new CreditAccount();
s.accountType();
c.accountType();
cr.accountType();
Output
This is a savings account This is a current account This is a credit account