In our third section on learning Java5 we look at the quadrumvirate of OO Concepts - encapsulation, inheritance, abstraction and polymorphism.
Up until now, for learning purposes, we have ignored many important object oriented concepts that we can use within our Java programs. This neglect is rectified in this section where we start our study of OO concepts by
looking at encapsulation and how to protect our data. We then tackle inheritance over two lessons where we look at creating hierarchies, overriding methods and the use of
super. After this we look at
abstraction and how we apply it to our classes and methods. We then examine polymorphism and how to use it with our methods, arguments and return types. Our investigation of polymorphism continues as we investigate interfaces
and their usage. We then return to the idea of encapsulation as we look into nested classes, what they are and how to use them. We finish the section with a detailed look at the
Object class and the methods
we inherit and can override in our subclasses.
Up until now we haven't really worried about our data and how we expose it to the outside world. In the real world we can't expose data like this, and we learn not to, as we look at encapsulation. So what can we do about protecting our data and what is encapsulation? Encapsulation is a language mechanism used to restrict access to an object's components and is the subject of this lesson.
This lesson introduces us to the OO concept of Inheritance and what it means. We also learn how we create inheritance hierarchies before tackling method overrides.
In our uses of inheritance in the previous lesson we looked at overriding a superclass method directly above the subclass we are in and all the classes used so far are a level below the top abstraction. We continue our investigation of inheritance and conceptualize where our objects fit into the hierarchy and also investigate superclass members, overrides and constructors.
In this lesson we continue our investigation of OO concepts by looking at abstraction. We get to grips with the concept of abstraction and the design reasons for using it. We then look at the application of abstraction within our own classes and methods
In this lesson we continue our investigation of OO concepts by learning about polymorphism, which roughly translated from the Greek means 'the ability to assume different forms'. We look at the benefits we get from using polymorphism and how we use it in our own code.
This lesson looks at interfaces and the contracts we provide when using them. We also delve deeper into polymorphism where we look at polymorphic interface arguments and polymorphic return types. We finish the
lesson by looking at using the
instanceof with interfaces.
This lesson is all about nested classes, which are classes defined within the curly braces of other classes. A nested class is only known to the enclosing class and shares its scope. This means that non-static nested classes have access to all the members and variables of the outer class. Conversely the outer class knows nothing of the internal working of the nested class.
We finish the section with a detailed look at the
Object class, the 'daddy' of all classes. All methods of the
Object class are inherited and so we examine the methods in the class,
paying particular attention to those we might need to override in our subclasses.