CHAPTER 8

INTRODUCING CLASSES

So far, we have studied many basic features of Java. We know that Java is a highly object-oriented language. The study of this aspect of the language starts with the concept of class. Let us study classes step by step in this chapter.

8.1 Class Fundamentals

8.1.1 The general form of a class

Class can be considered as nothing but a user-defined type. It is a template for the object to be created. It holds some data. This data can be of different simple types we have studied earlier.

Let us take an example of time. It consists of hours, minutes, and seconds. To store these quantities, we need three different fields (variables). But together they constitute a single object.

A class in general has two types of members. ...

Get Programming with Java now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.