Landing : Athabascau University

Unit 5

Last updated August 22, 2024 - 10:34am by Ans Thattil

Classes hence become blueprints for these objects, and with them, structure and some sets of behaviors are inherited by every individual object created. An instance is an object created from a class; the state of the object is held by instance variables, which are usually declared in a class but outside any method and maintain consistency throughout the class. The `null` keyword is employed to denote that the variables of the program refer to no object. Instance methods describe an object's behaviour; getters and setters have to do with accessing private instance variables, guarding an object from direct access to its internal state—an equally important principle called encapsulation. This is where constructors play their role in initializing new instances of a class. Called at the events of object creation, they can optionally set initial values for a number of attributes an object would have.

Well, at first, I was really confused with regards to this garbage collection thing until I hit upon the solution for Problem 3 of Assignment 2. Java automatically runs a process called garbage collection, which reclaims the memory occupied by an object that is no longer accessible. In so doing, it avoids problems like dangling pointers—your program referring to deleted objects—and memory leaks where an unused object is not deleted and therefore leads to memory overload. Garbage collection can be forced to happen with the `finalize()` method.

Polymorphism and inheritance are two concepts that have rendered coding a lot easier. A superclass in Java is a base class from which other subclasses inherit, thus forming an extension of the superclass. Inheritance is organized in a tree form, showing the relationships between classes. Polymorphism enables a method to change its behavior depending on the object it is called on. An abstract class is a template for subclasses and cannot be instantiated. A concrete class can be instantiated to create objects.

The chapter covers nested classes, such as classes defined within another class. Inner classes are a type of non-static nested class that cannot refer to non-static members of the outer class. Local classes are defined inside methods, constructors, or initialization blocks, and anonymous classes are unnamed for simple, immediate implementations, often used to implement interfaces.

This chapter has greatly improved my understanding of all concepts related to Java programming and their practical application.