Classes and Objects

Understand the concepts of classes and objects with the help of an interactive example in this lesson.

We'll cover the following

In the previous examples, we have seen that a Java program creates many objects. Objects interact with other objects by changing their states. When they change their states, they actually invoke the methods to do so.

These objects’ interactions accomplish many tasks, from simple to complex such as the implementation of a Graphical User Interface (GUI), an animation, or something else. We have also learned that behind an object there is a blueprint, a class. In those classes, we also set some rules so that one object can interact with other objects.

As you progress further, you will learn how we can make and break those rules to create different types of design patterns. Unfortunately, that is beyond our scope at present. We will have a very basic introduction to classes and objects to give you an idea of how they work.

Coding example: 85

In this example, we will see a parent or super MobileClass that has some typical states and methods that a mobile usually has. We also have a child or subclass ZenyClass (you may think about it as a new mobile company) that extends all those states and methods. Not only does ZenyClass extend all the features of the superclass, but it also has some of its own. At a later point, we have created two ZenyClass objects with different features.

Get hands-on with 1200+ tech skills courses.