Classes/Objects  «Prev  Next»


Lesson 11

Java Module Conclusion

The following list summarizes the important points that were covered in this module:
  1. A fully encapsulated class declares all of its variables as private and provides methods for getting and setting the properties represented by field variables.
  2. A non-inner class may specify the modifiers public, abstract, and final.
  3. A final class may not be extended.
  4. "is a" identifies subclass relationships, while "has a" identifies member variables.
  5. Constructors are not inherited.
  6. A default constructor is supplied by the compiler if no other constructors are provided.
  7. this() refers to a constructor of the same class. super() refers to a superclass constructor.
  8. Non-static inner classes may not have static members. Static inner classes may not have non-static members.
  9. Local inner classes may only access variables and parameters that are declared as final and assigned a value.
  10. Anonymous inner classes are unnamed inner classes that are declared and created at the same time.

Key terms and concepts

  1. Classification: The organization of information into hierarchical categories.
  2. Inheritance: The passing on of design information from a superclass to a subclass.
  3. Single inheritance: The inheritance of class members from a single parent.
  4. Multiple inheritance: The inheritance of class members from more than one parent.
  5. Encapsulation: A quality of classes with well-defined and controlled interfaces.
  6. Polymorphism: Having many forms.
  7. Dynamic binding: A program compilation and execution feature that allows programs to delay until Runtime decisions about the type of objects that they access.
  8. Abstract method: A method whose implementation is deferred to a subclass. A method declared abstract cannot also be declared to be private, static, final, native, strictfp, or synchronized .
  9. Member: An element of a class or interface, such as a field variable, method, or inner class. An element of a package, such as a class, interface, or subpackage.
  10. Subclass: A class that extends another class. All classes are a subclass of themselves.
  11. Superclass: A class that is extended by another class.
  12. Strict subclass: A subclass that is not the class itself.
  13. Direct superclass: The class that is identified in a class's extends clause. If a class is declared without an extends clause, then its direct superclass is java.lang.Object.
  14. Access modifier: A modifier that is used to limit access to a class, class member, or constructor.
  15. Nested class: A class that is declared as a member of another class or interface.
  16. Enclosing scope: The instance of an outer class in which an instance of an inner class is created
  17. Top-level class: A class that is not nested or a static inner class.
  18. Scope: The extent of the context of a definition.
  19. Local inner class: An inner class that is declared local to a block of code.

Theory behind Encapsulation

When using an object oriented programming paradigm, objects encapsulate only local data, which is by default accessible only by the object itself. Rather than having to think about data and code as two separate concepts, an object oriented program merges the two in the concept of an object.
This increases understanding (analysts and programmers can consider objects of interest without internalizing the workings of the complete program) and ease of maintenance. To realize the latter, object-oriented programming applies two concepts known as 1) encapsulation and 2) information hiding. One of the greatest sources of errors in programs is when some parts of the program are interfering with other parts.
The addition of more procedures and data will quickly lead to unstructured code, where it difficult to follow the trace of execution as data can jump from one part to another in the program. Object-oriented programming resolves this issue by encapsulating of the data and behavior within an object.
However, this in itself is not sufficient to guarantee maintainable programs, as you also need to prevent the data of an object from being directly accessible by other objects. Therefore, object-oriented programming also emphasizes the concept of information hiding, where an object's data can by default be accessed only by methods contained in the same object.
When data elements of one object need to be used by another object, the latter must call a publicly accessible method, , basically requesting the "owning object" to perform a change to its data (setter). As such, object-oriented programming encourages programmers to place data where it is not directly accessible(getter) or modifiable by the rest of the system. Instead, the data is accessible through methods, which can also include checks to make sure the requested change is permitted by the owning object. Object-oriented programming also defines concepts to help with structuring programs so that they can be easily extended and evolved. These concepts are 1) polymorphism, which is the ability to treat objects of different types in a similar manner, and 2) inheritance, which is a concept to allow for extending objects and enabling code reuse.

Anonymous Class - Quiz

Click the Quiz link below to check your understanding of Java classes, interfaces, and objects.
Anonymous Class - Quiz