Attributes (OOP) (OCR A Level Computer Science)

Revision Note

Craig Godbold

Expertise

Computer Science

Attributes (OOP)

What is an Attribute?

  • In object-oriented programming (OOP), an attribute refers to a data member or a property associated with an object or a class

  • They define the state of an object and can have different values for different instances of the same class

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

  • Attributes can have different access rights

  • The example below shows a Car class object with an attribute called manufacturer

  • It has a private access meaning that it can be accessed only by instances of the Car class

  • The data that this attribute will hold must be of the String data type

  • The image below gives a visual representation of an object of this class being instantiated with a data value of “Ford” :

An example instance of an object

An example instance of an object

  • In most cases each class has many different attributes

  • Below is an example of an object of class "person":

Example of an object of class "person"

Example of an object of class "person"

Exam Tip

  • Attributes declared within methods (local variables) cannot have access modifiers because they are local to the method and have a limited scope

  • Local variables are only accessible within the block or method in which they are declared. They are not part of the class's state and cannot be accessed from other methods or classes

You've read 0 of your 0 free revision notes

Get unlimited access

to absolutely everything:

  • Downloadable PDFs
  • Unlimited Revision Notes
  • Topic Questions
  • Past Papers
  • Model Answers
  • Videos (Maths and Science)

Join the 100,000+ Students that ❤️ Save My Exams

the (exam) results speak for themselves:

Did this page help you?

Craig Godbold

Author: Craig Godbold

Craig is an experienced educator with 14 years of teaching experience in the UK, USA, and China, He has held a variety of roles in education, including Head of Faculty, IB teacher and now currently teaches A level and GCSE courses. Craig supported his students to achieve the best results the school had ever had in IB Computer Science.