CS Grade 9-12

Object-Oriented Programming: Classes and Objects

Practice identifying classes, objects, attributes, and methods

View Answer Key
Name:
Date:
Score: / 12

Practice identifying classes, objects, attributes, and methods

CS - Grade 9-12

Instructions: Read each problem carefully. Write clear answers using complete sentences. When asked to write code, use readable pseudocode or a programming language you know.
  1. 1
    A generic car blueprint points to three different car objects.

    In object-oriented programming, explain the difference between a class and an object. Use the example of a Car class in your explanation.

  2. 2

    A Student class has the attributes name, gradeLevel, and gpa. Write two different Student objects with realistic values for each attribute.

  3. 3
    A game character is shown with health, coins, and action icons.

    Identify the class, object, attributes, and methods in this situation: A video game has a Player class. One player is named Alex. Alex has 80 health points and 150 coins. Alex can jump, attack, and collect coins.

  4. 4

    Design a Book class for a library program. List at least four attributes and at least three methods that would make sense for the class.

  5. 5

    A class called BankAccount has attributes accountHolder and balance. It has methods deposit(amount) and withdraw(amount). Explain what should happen when deposit(50) is called on an object with a current balance of 125.

  6. 6

    Write simple pseudocode for a Dog class with the attributes name and age and a method bark() that prints a short message using the dog's name.

  7. 7

    A programmer creates three objects from a Phone class: phone1, phone2, and phone3. Explain why each object can have a different batteryLevel even though all three objects come from the same class.

  8. 8
    A gridded rectangle with width and height arrows shows an area model.

    Read this pseudocode: class Rectangle has attributes width and height. It has a method area() that returns width times height. If rect1 has width 6 and height 4, what should rect1.area() return? Explain your answer.

  9. 9

    Explain why constructors are useful when creating objects. Use an example involving a Movie class.

  10. 10

    A Temperature class stores a temperature in Celsius using an attribute called celsius. It has a method toFahrenheit() that returns celsius times 9 divided by 5 plus 32. If temp1.celsius is 20, what should temp1.toFahrenheit() return? Show the calculation.

  11. 11

    A class called Playlist has an attribute songs, which stores a list of song titles. It has a method addSong(title). Explain what the method should do and how it changes a Playlist object.

  12. 12

    Choose a real-world object that could be modeled in software. Name the class, describe one possible object, list three attributes, and list two methods.

LivePhysics™.com CS - Grade 9-12

More CS Worksheets

See all CS worksheets

More Grade 9-12 Worksheets

See all Grade 9-12 worksheets