Back to 课程

Computer-Science-A-level-Ocr

0% Complete
0/0 Steps
  1. 3-3-networks
    8 主题
  2. 3-2-databases
    7 主题
  3. 3-1-compression-encryption-and-hashing
    4 主题
  4. 2-5-object-oriented-languages
    7 主题
  5. 2-4-types-of-programming-language
    4 主题
  6. 2-3-software-development
    5 主题
  7. 2-2-applications-generation
    6 主题
  8. 2-1-systems-software
    8 主题
  9. 1-3-input-output-and-storage
    2 主题
  10. 1-2-types-of-processor
    3 主题
  11. 1-1-structure-and-function-of-the-processor
    1 主题
  12. structuring-your-responses
    3 主题
  13. the-exam-papers
    2 主题
  14. 8-2-algorithms-for-the-main-data-structures
    4 主题
  15. 8-1-algorithms
    10 主题
  16. 7-2-computational-methods
    11 主题
  17. 7-1-programming-techniques
    14 主题
  18. 6-5-thinking-concurrently
    2 主题
  19. 6-4-thinking-logically
    2 主题
  20. 6-3-thinking-procedurally
    3 主题
  21. 6-2-thinking-ahead
    1 主题
  22. 6-1-thinking-abstractly
    3 主题
  23. 5-2-moral-and-ethical-issues
    9 主题
  24. 5-1-computing-related-legislation
    4 主题
  25. 4-3-boolean-algebra
    5 主题
  26. 4-2-data-structures
    10 主题
  27. 4-1-data-types
    9 主题
  28. 3-4-web-technologies
    16 主题
课 Progress
0% Complete

Classes (OOP)

What is a class?

  • Classes are used as blueprints or templates that can be used to create objects within Object Oriented Programming or OOP

  • An object is created from a specific instance of a class and has its own state and behaviours

  • Using this method allows for reusable and organised code in a modular way

  • Consider a class of students

    • Each student has a name, a date of birth and gender

  • Therefore we can create a blueprint or template for all students by making a class which contains these three attributes

  • As each student (or object) is created they will each have their own name, date of birth and gender attributes along with their own state for example

    • Name “John”

    • Date of birth “06/10/2015”

    • Gender “Male”

  • Some classes are already prebuilt into a programming language saving the developer from having to write them from scratch and often provide common functionality

  • Examples from Java include:

    • Date and calendar when working with dates

    • String when working with strings of text

    • Random when generating random numbers

    • Scanner when reading input from a user or file

  • Custom classes are created by the programmer to define new data types

  • For example, a class for animals does not exist and so the programmer must define a custom class

  • Instantiation is the term used for creating an object from a class

  • Each class contains attributes which are essentially variables within a class and are also known as Class Variables

  • Objects that are created from a class contain attributes which are also known as instance variables

  • Classes can also contain methods/functions/procedures

  • Methods are actions or behaviours that can be performed

  • The name that is used to refer to an object is known as the identifier

  • Below is a visual representation of both a class and objects that have been instantiated

  • In the image below, the identifiers are P1 and P2

Example of a class and objects

Example of a class and objects

Examiner Tips and Tricks

  • Although you may see the terms methods/functions/ procedures, a method can be either a function or a procedure

  • A function is a method that must return a value

  • A procedure is a method that does not need to return a value

Worked Example

What is a class in object-oriented programming (OOP) ?

[2]

How to answer this question:

  • Classes provide a way to organize code in a modular way [1]

  • A blueprint or template for creating objects with specific attributes [1]

Answer:

 Example answer to get full marks:

A class is acts as a blueprint or template for creating objects with specific attributes [1 mark], while also providing a way to organize code in a modular fashion. [1 mark]

Responses

您的邮箱地址不会被公开。 必填项已用 * 标注