Object-Oriented Programming: Classes and Objects
Practice identifying classes, objects, attributes, and methods
Practice identifying classes, objects, attributes, and methods
CS - Grade 9-12
- 1
In object-oriented programming, explain the difference between a class and an object. Use the example of a Car class in your explanation.
- 2
A Student class has the attributes name, gradeLevel, and gpa. Write two different Student objects with realistic values for each attribute.
- 3
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
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
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
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
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
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
Explain why constructors are useful when creating objects. Use an example involving a Movie class.
- 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
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
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.
Related Tools
Related Labs
Related Cheat Sheets
More CS Worksheets
CS: Algorithms and Flowcharts
Grade 6-8 · 12 problems
CS: Arrays and Lists
Grade 9-12 · 12 problems
CS: Big-O Notation and Algorithm Efficiency
Grade 9-12 · 12 problems
CS: Binary Numbers and Number Systems
Grade 6-8 · 12 problems
More Grade 9-12 Worksheets
Linear Equations
Math · 8 problems
Cell Biology
Biology · 8 problems
Reading Comprehension
Language Arts · 8 problems
Historical Thinking & Evidence
Social Studies · 8 problems