Question: In object-oriented programming, the concept of encapsulation hides the implementation details of a class and forces the user to use an interface to access data.
In object-oriented programming, the concept of encapsulation hides the implementation details of a class and forces the user to use an interface to access data. This helps to make the code more maintainable. (a) Define a Java class named Vehicle with at least THREE (3) instance variables with private access modifiers. One of these instance variables will be the price and the category. Define THREE (3) getter and TWO (2) setter instance methods to access or modify any of the object's instance variables. One of the setter methods is used to set the value of the price instance variable. If the price value given is above 100000, the category will be assigned as "Luxury", else it will be assigned as "standard" by default. (15 marks) (b) Define another Java class with the main() method to demonstrate the access and manipulation of the object Vehicle above. Demonstrate the use of all the getter and setter methods defined in the vehicle class. Show the results of the vehicle default category when the initial price is 100000 or less, and the updated category when the price is set to above 100000
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
