Keyboard shortcuts

Press ← or → to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

Object Oriented

Exercises

Class

  1. Write a class Person with a constructor fields name and a method sayHello
  2. Instantiate the Person and call the sayHello method

Companion Object

  1. Write an object Person with a method apply
  2. Instantiate a Person with the companion object

Case Class

  1. Write a case class Person with a constructor field name and a method sayHello
  2. Instantiate the Person (with the generated companion object)

Inheritance

  1. Write a class Customer with a constructor field name that extends Person
  2. Instantiate the Customer and call the sayHello method

Trait

  1. Write a trait Greeter with a sayHello method
  2. Use the Greeter on the Customer and call the sayHello method