By default, the compiler will generate each of these operations if a program uses it. However, if the programmer declares any constructor for a class, the default constructor for that class is not generated. If the programmer declares a copy or move operation, no copy, move or destructor is generated. If the programmer declares a destructor, no move operation is generated (a copy constructor is generated for backward compatibility).
We can also suppress generation of specific operations with the =delete pseudo-initialiser:
class X {
public:
X (const X&) =delete; // suppress the compiler-generated copy operations
X& operator=(const X&) =delete;
// ...
};
Unless you define your own, the compiler generates a default constructor, a copy constructor, a move constructor, a copy assignment operator, a move assignment operator and a destructor.
It depends on how the class is declared.If the class is a normal class - Then the compiler will complain. All the methods in an interface must be implemented by the class to successfully compile the classIf the class is declared as abstract - Then the compiler will ignore the fact that a few methods are not implemented
No. Classes can only have one destructor, whether you define one yourself or allow the compiler to generate one for you. The compiler-generated destructor is public by default, does not release any memory allocated to any class' member pointers, and is non-virtual, which are the three main reasons for defining your own.
Yes. There is no specific order in which the compiler expects methods to be present. As long as the method is inside the class it is perfectly fine.
Yes. Any class that does not provide implementation to all its methods as well as its parent class methods needs to be Abstract. The Java compiler would not successfully compile a class that does not do this.
Inheritance allows a new class to automatically pick up all the protected and public data and methods of an existing class. To do so, the new class must be derived from the existing class. Private data and methods remain private to the existing class, the base class.
Constructors are used to initialise the members of a class whenever you instantiate objects from the class. If you do not specify any constructors, the compiler will automatically generate a default, a copy and a move constructor for you. The compiler will also generate matching copy and move assignment operators, as well as a destructor. The advantage of providing your own constructors is to provide alternative methods of initialising objects of the class. For instance, being able to implicitly convert from one class to another is achieved through a conversion constructor, along with a matching conversion assignment operator. If your object allocates low-level resources, you will also want to override the compiler-generated constructors and assignment operators to ensure those resource are correctly initialised, deep-copied and released. The compiler won't do it for you.
bottom up methods
That means you have two (or more) methods with the same name, but with different signatures - that is, the number or types of parameters are different. The compiler will automatically choose the correct method, according to the parameters provided.
The keyword super is used to explicitly call methods/values from the parent class The keyword this is used to explicitly call methods/values from the current class
It depends on how the class is declared.If the class is a normal class - Then the compiler will complain. All the methods in an interface must be implemented by the class to successfully compile the classIf the class is declared as abstract - Then the compiler will ignore the fact that a few methods are not implemented
An IllegalArgument exception is usually generated when the arguments passed to a method do not match the data type of the arguments the method expects. Most of these problems are caught by the compiler but in cases where Java Reflection is used to generate and call methods dynamically, we can often encounter this exception.
Yes. There is no specific order in which the compiler expects methods to be present. As long as the method is inside the class it is perfectly fine.
No. Classes can only have one destructor, whether you define one yourself or allow the compiler to generate one for you. The compiler-generated destructor is public by default, does not release any memory allocated to any class' member pointers, and is non-virtual, which are the three main reasons for defining your own.
RAID
False. Overloaded methods must have different parameters defined.A different return type alone would not help the compiler determine which method to choose at compile time.
Yes. There is no specific order in which the compiler expects methods to be present. As long as the method is inside the class it is perfectly fine.
"Collectively, the methods used to improve performance and automatically recover from a failure are called RAID(redundant array of inexpensive disks or redundant array of independent disks).(Pg. 480, A+ Guide to Managing and Maintaining Your PC)