Java is arguably the hottest programming language today. It can be used cross platform to build complete applications, applets and even web pages. In this 10 part series of articles, Chris will explain what Java is, and also provide working examples, clearly describing the Java language syntax.
Java Part 1: The Basics - What are objects? (Page 3 of 5 )
Objects in Java and other object-orientated languages contain both data members and the methods (functions) that operate on those members.
Because of this, encapsulation is achieved and objects will function more reliably with other independent code. Objects are simply instances of classes. Methods and members that are contained within an object are accessible with the dot (.) operator, such as myObject.DoWork(). We will explore objects later in the series.
Why code twice when once will do?
The answer?... Don't! As well as any user defined classes that one may wish to implement, Java comes with a great many predefined classes so one need not re-invent the wheel every time new code is needed. This can greatly expedite the coding and design process.
In Java, classes can be extended from existing classes. The descendant class extends its parent class by inheriting its attributes and defining extra ones. This is called inheritance. Inheritance is useful when a class is very similar to another class, but needs additional methods or members. Inheritance saves a lot of code duplication.
Another example of a form of inheritance is class abstraction. Abstract classes and their descendents make use of the same methods, although the methods for each descendent class will perform different actions specific to the nature of the class. This is a powerful feature of the object-orientated paradigm that will also be explored in more detail later down the track.