Java Exercises

Creating Class and methods – Java OOP Exercise

Java OOP exercise to learn how to create class and methods by reading requirements. Exercise-1: Create a class Dog, that has 3 properties (class fields) breed, age and colour with behaviours (class method) bark and sleep. Exercise-2: There is a car, which has attributes model and price, and the car has functionalities start, stop and […]

Shape Interface Implementation: Java Exercise

EXERCISE: Create a Shape interface having methods area () and perimeter (). Create 2 subclasses, Circle and Rectangle that implement the Shape interface. Create a class Sample with main method and demonstrate the area and perimeters of both the shape classes. You need to handle the values of length, breath, and radius in respective classes to […]

Java Exercise – On Constructor with Solution

Java exercises on constructor with solutions. EXERCISE-1: Answer the following questions in brief. When a class constructor gets called? If you create 5 objects of a class, then how many time constructors will be called? When you write a constructor, what return type do you write in constructor declaration? Why do you use constructor? EXERCISE-2: […]

Scroll to top