1. Learn
  2. /
  3. Courses
  4. /
  5. Introduction to Object-Oriented Programming in Java

Connected

Exercise

Public class fields

So far, during this course, you have created properties and methods without specifying access modifiers. You will explicitly specify the public access modifier for the appropriate properties within your code.

NOTE: In Java, properties without explicit access modifiers are package-private by default, allowing access similar to public. Also, only one class per file can be explicitly marked as public.

Instructions

100 XP
  • Mark the model, and year properties of the Car class public by adding the public access modifiers to them.
  • Turn both the turnEngineOn and calculateMPG methods public by adding the public access modifiers to them.