CHAPTER 5

Defining a Class in Java

In Chapter 3 we have seen that a class is a reference data type. Just like we have primitive data types in Java, which are predefined by the Java language, classes are also data types, but these are defined by a programmer. Just like we can use the primitive data in different applications, the classes defined by a programmer can also be reused in a number of applications.

The methods in a class are like the operators for the data type (class). In Exercise 2.1, we defined the class HelloWorld as a place holder for the Java application. A Java application is defined in a method called main(), so let us call those classes that contain the application (method main) as an application class. All classes need not contain ...

Get The class of 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.