OOP in Java
As discussed in the previous chapters, while Java has primitive types, everything else is an object. While Java is not considered a pure OOP language because of its support for primitive types, it is still a serious OOP language.
To use Java effectively, you should know OOP. Don't worry if your OOP knowledge is rusty. While this chapter does not teach it, we will try to refresh your memory along the way. This chapter concentrates on all OOP-related subjects:
- Defining classes
- Defining packages
- Adding class members: variables and methods
- Constructors and deconstructors
- Inheritance
- Interfaces
- Abstract classes
- Upcasting and downcasting
Defining classes
As we have seen in the examples from previous chapters, a class can simply be defined with Java's class
keyword, followed by the class name and brackets { }
. The brackets visually show the programmer what code is part of the class:
class ClassName { }
The preceding code will compile. It complies with all Java's syntax rules. Removing any...