Questions of interview
0x01 Terminology 術語
class / object
A class is a user-defined blueprint or prototype from which objects are created.
An object is a basic unit of Object Oriented Programming and represents the real-life entities.
instantiation
Instantiation is a process of taking a class definition and creating an object that can use in a program.
virtual method / pure virtual method
A virtual function or virtual method is a function or method whose behavior can be overridden within an inheriting class by a function with the same signature.
A pure virtual function or pure virtual method is a virtual function that is required to be implemented by a derived class that is not abstract
In Java, all non-static methods are by default “virtual functions.” Only methods marked with the keyword final, which cannot be overridden, along with private methods, which are not inherited, are non-virtual.
constructor
A constructor is a method has the same name with class, used to initialize when an object is created.
destructor / finalizer
Java is a garbage collected language that we cannot predict when (or even if) an object will be destroyed. Hence there is no direct equivalent of a destructor.
There is an inherited method called finalize, but this is called entirely at the discretion of the garbage collector.
superclass or base class / subclass or derived class
A class that is derived from another class is called a subclass (also a derived class, extended class, or child class). The class from which the subclass is derived is called a superclass (also a base class or a parent class).
delegation / composition / aggregation
Delegation: When my object uses another object's functionality as is without changing it.
Composition (has-a): My object consists of other objects which in turn cannot exist after my object is destroyed-garbage collected.
Aggregation: My object consists of other objects which can live even after my object is destroyed.