2.5 Object Oriented Languages (OCR A Level Computer Science) Flashcards

Exam code: H446

1/55

0Still learning

Know0

  • Define class in Object Oriented Programming (OOP).

Cards in this collection (55)

  • Define class in Object Oriented Programming (OOP).

    A class is a blueprint or template used to create objects with specific attributes and behaviours in Object Oriented Programming.

  • An object is created from a class using a process called        .

    An object is created from a class using a process called instantiation.

  • What is an object in OOP?

    An object is a specific instance of a class that has its own state and behaviours.

  • In OOP, the name used to refer to an object is called its         .

    In OOP, the name used to refer to an object is called its identifier.

  • True or False?

    Methods within a class can only be functions, not procedures.

    False.

    A method can be either a function (returns a value) or a procedure (does not return a value).

  • Define attributes in the context of classes.

    In classes, attributes are variables that store data about each object created from the class. They are also known as instance variables.

  • Give an example of a prebuilt class in Java and its use.

    The String class is prebuilt in Java and is used to work with strings of text.

  • A        is created by the programmer to define new data types that do not already exist in a language.

    A custom class is created by the programmer to define new data types that do not already exist in a language.

  • Define object in programming.

    An object is a representation of a real-world entity, such as a teacher, aeroplane, or mobile phone, created from a class in object-oriented programming.

  • What is the difference between a class and an object in OOP?

    A class is a blueprint that describes the properties and behaviours of objects, while an object is a specific instance created from that class, with its own unique values for those properties.

  • A        is a special method within a class that is automatically called when an object is created.

    A constructor is a special method within a class that is automatically called when an object is created.

  • Define constructor in object-oriented programming.

    A constructor is a special method in a class that sets initial values of instance variables and prepares the object for use when it is instantiated.

  • A class acts as a          that describes the properties and behaviours of objects.

    A class acts as a blueprint that describes the properties and behaviours of objects.

  • True or False?

    A constructor is only called manually after an object has been created.

    False.

    A constructor is called automatically when an object is instantiated, not manually after creation.

  • What is the purpose of a constructor in a class?

    A constructor defines the initial values of instance variables and performs any necessary setup for the object when it is created.

  • To create an object called mushypeas of type ItemForSale with the name “mushy peas” and price £0.89, you write:                          .

    To create an object called mushypeas of type ItemForSale with the name “mushy peas” and price £0.89, you write: mushypeas = new ItemForSale("mushy peas", 0.89).

  • Define method in object-oriented programming.

    A method is a function associated with a class or object that defines the behaviours and actions that objects can perform in object-oriented programming.

  • What is the difference between a function and a procedure in the context of methods?

    A function returns a value after performing a task, while a procedure performs a task but does not return a value.

  • Objects created from a class can use its methods by accessing them with the      notation (for example, jumboJet.Takeoff()).

    Objects created from a class can use its methods by accessing them with the dot notation (for example, jumboJet.Takeoff()).

  • True or False?

    Static methods are associated with objects and operate on specific instance data.

    False.

    Static methods are associated with the class itself and can be called without creating an instance; they do not operate on specific instance data.

  • Define instance method.

    An instance method is a method associated with an individual object, operating on its data and properties.

  • What is the main purpose of private methods in a class?

    Private methods are used to hide internal implementation details and can only be accessed within the same class, which helps organize and manage code internally.

  • When a method does not specify the keyword       or       , its default value is set to       .

    When a method does not specify the keyword public or private, its default value is set to public.

  • Why should changes to public methods be made carefully?

    Changes to public methods may affect other parts of the codebase that depend on them, so they should be carefully designed and remain backward compatible whenever possible.

  • Define attribute in object-oriented programming.

    An attribute is a data member or property associated with an object or a class in object-oriented programming, used to define the state of an object.

  • What do attributes define in an object?

    Attributes define the state of an object and can have different values for different instances of the same class.

  • True or False?

    Attributes in OOP can only be of integer or string data types.

    False.

    Attributes can be of various data types, such as integers, strings, Booleans, or even other objects.

  • Attributes can have different         rights, controlling how they are accessed.

    Attributes can have different access rights, controlling how they are accessed.

  • What does it mean if a class attribute is private?

    A private attribute can only be accessed by instances of the class it belongs to, not from outside the class.

  • Why might a class have many different attributes?

    A class usually has many different attributes to represent all aspects of its state, such as a person object having a name, age, and address.

  • True or False?

    Attributes declared within methods can have access modifiers.

    False.

    Attributes declared within methods are local variables, which cannot have access modifiers and are only accessible within the block or method where they are declared.

  • Define inheritance in object-oriented programming.

    In object-oriented programming, inheritance is when a class acquires the properties and methods of another class, allowing code reuse and establishing an IS-A relationship.

  • What is the main benefit of using inheritance in programming?

    The main benefit of inheritance is that it promotes code reuse by allowing derived classes to use existing code from a base class, improving organisation and maintainability.

  • Inheritance establishes an       relationship between the base class and the derived class.

    Inheritance establishes an IS-A relationship between the base class and the derived class.

  • True or False?

    A derived class can add new attributes and methods in addition to those inherited from the base class.

    True.

    A derived class can add its own attributes and methods as well as inherit from the base class.

  • What is a parent class?

    A parent class (also known as a base or superclass) is a class that defines common properties and behaviours to be inherited by derived classes.

  • What is a child class?

    A child class (also called a derived or subclass) inherits attributes and methods from a base class and can add its own functionality.

  • The       keyword is used to refer to the superclass and access its members from the subclass.

    The super keyword is used to refer to the superclass and access its members from the subclass.

  • With reference to the classes office and house inheriting from building, what does inheritance mean?

    Inheritance means that the office and house classes (derived classes) gain the attributes and methods of the building base class.

  • Define encapsulation.

    Encapsulation is the practice of grouping data (attributes) and methods (functions) within a class, restricting direct access to some of the object's components to improve security and organisation.

  • What is the main purpose of using encapsulation in object-oriented programming?

    The main purpose of encapsulation is to secure data and prevent accidental modification or misuse by controlling access to attributes and methods through access modifiers.

  • Encapsulation helps to organise code by keeping related     and       together within an object.

    Encapsulation helps to organise code by keeping related data and methods together within an object.

  • True or False?

    Encapsulation allows external code to directly access private variables inside a class.

    False.

    Encapsulation hides private variables from external code; they can only be accessed or modified through public methods.

  • A class can use       variables to ensure that data can only be changed using        .

    A class can use private variables to ensure that data can only be changed using public methods.

  • How does encapsulation promote code reusability?

    Encapsulation promotes code reusability by allowing the same object or class to be used in different parts of a program without rewriting code, because its internal details are hidden.

  • What is the role of abstraction in encapsulation?

    Abstraction in encapsulation reduces complexity by hiding implementation details, making objects easier to use and understand.

  • In the Obstacle class example, how is encapsulation achieved for the distance attribute?

    Encapsulation is achieved by declaring distance as private and providing a public method updateDistance() to modify its value.

  • Define polymorphism in object-oriented programming.

    In object-oriented programming, polymorphism is the concept that allows objects to take on different forms or behaviours, enabling code to be more flexible, reusable, and easier to maintain.

  • What advantage does polymorphism provide in programming?

    Polymorphism provides flexibility and reusability to code, making it easier to write, manage, and adapt programs.

  • Polymorphism allows       to share the same name or behaviour, but work in different ways.

    Polymorphism allows objects to share the same name or behaviour, but work in different ways.

  • What is method overloading in the context of polymorphism?

    Method overloading is a feature of polymorphism that allows multiple methods with the same name to exist in a class, each with different implementations or parameters.

  • True or False?

    The override keyword is used in polymorphism to provide a new implementation for a method in a subclass.

    True.

    The override keyword allows a subclass to provide a new implementation for a method defined in its parent class.

  • In method overriding, the      class provides its own implementation of a method defined in the      .

    In method overriding, the child class provides its own implementation of a method defined in the parent class.

  • How does polymorphism help in treating objects as a common group?

    Polymorphism allows objects of different classes to be treated as members of a common superclass, making code more versatile and adaptable.

  • An array of type        can store both      and        objects due to polymorphism.

    An array of type Vehicle can store both Car and Motorcycle objects due to polymorphism.

Sign up to unlock flashcards

or