Script Valley
Java: Complete Language Course
Object-Oriented Programming in Java/Assessment

Practice & Assessment

Test your understanding of Object-Oriented Programming in Java

Multiple Choice Questions

5
1

What does the this keyword refer to inside a Java constructor?

2

A class has a private field. External code calls a setter that validates the value before assigning. What OOP principle does this demonstrate?

3

Which statement about Java inheritance is correct?

4

What happens when an Animal reference holds a Dog object and speak() is called?

5

What is the key difference between an abstract class and an interface in Java?

Coding Challenges

1
1

Shape area calculator with polymorphism

Create an abstract class Shape with an abstract method area() returning double. Implement three subclasses: Circle (radius), Rectangle (width, height), and Triangle (base, height). Write a method printAllAreas(Shape[] shapes) that loops through an array and prints each shape's type and area using polymorphism — no instanceof checks. Test with an array containing at least one of each shape. Input: hardcoded array of shapes. Output: each shape's class name and computed area. Time estimate: 20–25 minutes.

Medium

Mini Project

1

Mini Library Book System

Model a library using OOP. Create an abstract class LibraryItem with private fields title, author, isbn, and abstract method getSummary(). Create subclasses Book (adds pageCount) and AudioBook (adds durationMinutes), each overriding getSummary(). Add an interface Borrowable with methods checkOut(String borrowerName) and returnItem() plus a default method isAvailable() that tracks state. Make both Book and AudioBook implement Borrowable. Build a Library class with an ArrayList of LibraryItem. Add methods: addItem(), findByTitle(String), listAvailable(), and checkOutItem(String isbn, String borrower). Write a main method that adds 5 items, checks out 2, lists available items, and demonstrates polymorphism by iterating all items and calling getSummary().

Medium