Computer-Science-A-level-Ocr
-
3-3-networks8 主题
-
3-2-databases7 主题
-
3-1-compression-encryption-and-hashing4 主题
-
2-5-object-oriented-languages7 主题
-
2-4-types-of-programming-language4 主题
-
2-3-software-development5 主题
-
2-2-applications-generation6 主题
-
2-1-systems-software8 主题
-
1-3-input-output-and-storage2 主题
-
1-2-types-of-processor3 主题
-
1-1-structure-and-function-of-the-processor1 主题
-
structuring-your-responses3 主题
-
the-exam-papers2 主题
-
8-2-algorithms-for-the-main-data-structures4 主题
-
8-1-algorithms10 主题
-
7-2-computational-methods11 主题
-
7-1-programming-techniques14 主题
-
capturing-selecting-managing-and-exchanging-data
-
entity-relationship-diagrams
-
data-normalisation
-
relational-databases
-
hashing
-
symmetric-vs-asymmetric-encryption
-
run-length-encoding-and-dictionary-coding
-
lossy-and-lossless-compression
-
polymorphism-oop
-
encapsulation-oop
-
inheritance-oop
-
attributes-oop
-
methods-oop
-
objects-oop
-
capturing-selecting-managing-and-exchanging-data
-
6-5-thinking-concurrently2 主题
-
6-4-thinking-logically2 主题
-
6-3-thinking-procedurally3 主题
-
6-2-thinking-ahead1 主题
-
6-1-thinking-abstractly3 主题
-
5-2-moral-and-ethical-issues9 主题
-
5-1-computing-related-legislation4 主题
-
4-3-boolean-algebra5 主题
-
4-2-data-structures10 主题
-
4-1-data-types9 主题
-
3-4-web-technologies16 主题
-
environmental-effects
-
automated-decision-making
-
computers-in-the-workforce
-
layout-colour-paradigms-and-character-sets
-
piracy-and-offensive-communications
-
analysing-personal-information
-
monitoring-behaviour
-
censorship-and-the-internet
-
artificial-intelligence
-
the-regulation-of-investigatory-powers-act-2000
-
the-copyright-design-and-patents-act-1988
-
the-computer-misuse-act-1990
-
the-data-protection-act-1998
-
adder-circuits
-
flip-flop-circuits
-
simplifying-boolean-algebra
-
environmental-effects
polymorphism-oop
Polymorphism (OOP)
What is polymorphism?
-
In A Level Computer Science, polymorphism is a concept in programming that allows objects to take on different forms or behaviours.
-
Different objects can share the same name or behaviour but can work in different ways
-
It helps make code more flexible, reusable, and easier to maintain
-
It allows flexibility and reusability in programming, making it easier to write and manage code
-
Objects can be treated as belonging to a common group, even if they belong to different classes, making your code more versatile and adaptable to changes
Example 1 – method overloading

Method Overloading Example 1
-
In the example above, all three classes all have a method named
move(). Polymorphism allows methods to be declared with the same name but execute different code (in this case printing different messages) -
The override keyword Is used to provide a new implementation for a method that is already defined in the parent class (base class)
Example 2 – method overriding

Method Overriding Example 2
-
In the above example, both the Motorcycle class and the Car class inherit from the base class Vehicle
-
Objects from the Motorcycle and Car classes can call the
startEngine()method, which will output “Engine Started!“ -
If either of the object types calls the
displayInfo()method, the program will execute the method from the object’s class, as it overrides the method from the Vehicle class -
For example:
-
If a Motorcycle object calls the
displayInfo()method, “I am a Motorcycle!“ will be output -
If a Car object calls the
displayInfo()method, “I am a Car!“ will be output
-
Treating objects as common groups
-
Polymorphism also allows objects of different classes to be treated as objects of a common superclass or base class
-
For example:
-
Vehicle vehicle1 = new Car() -
Vehicle vehicle2 = new Motorcycle()
-
-
This allows an array of type Vehicle to store both Motorcycle and Car objects rather than in separate data structures
-
If the
vehicle1.displayInfo()method is called, it will still output “I am a Car!” -
If the
vehicle2.displayInfo()method is called, it will still output “I am a Motorcycle!”
-
-
This flexibility provided by polymorphism are essential for creating more maintainable and modular code
Responses