Întrebare |
Răspuns |
can you create an object of an abstract class? începe să înveți
|
 |
|
|
|
why do we have abstract classes? începe să înveți
|
|
An abstract class gives a way of grouping common members (data and methods) of its subclasses.
|
|
|
how do you declare an abstract class or method? începe să înveți
|
|
with the key word abstract
|
|
|
Why using an abstract class and not an ordinary superclass? începe să înveți
|
|
To force the subclasses to provide and implement certain methods.
|
|
|
what is a method signature? începe să înveți
|
|
the method name and the number, type and order of its parameters. Return types and thrown exceptions are not considered to be a part of the method signature.
|
|
|
începe să înveți
|
|
Polymorphism is the capability of a method to do different things based on the object that it is acting upon. In other words, polymorphism allows you define one interface and have multiple implementations
|
|
|
începe să înveți
|
|
more than one method having the same name, if their argument lists are different.
|
|
|
începe să înveți
|
|
Declaring a method in sub class which is already present in parent class is known as method overriding. Overriding is done so that a child class can give its own implementation to a method which is already provided by the parent class.
|
|
|
what is the advantage of overriding? începe să înveți
|
|
The main advantage of method overriding is that the class can give its own specific implementation to a inherited method without even modifying the parent class code.
|
|
|
why is overriding an example of runtime time (or dynamic polymorphism)? începe să înveți
|
|
When a parent class reference points to the child class object then the call to the overridden method is determined at runtime, because during method call which method(parent class or child class) is to be executed is determined by the type of object.
|
|
|
what is dynamic method dispatch? începe să înveți
|
|
This process in which a call to the overridden method is resolved at runtime
|
|
|
what are the rules for overriding? începe să înveți
|
|
Type signatures must match and access modifyers of the overriding method(subclass method) cannot be more restrictive
|
|
|
what are the 3 ways to overload a method? începe să înveți
|
|
change Number of parameters, Data type of parameters, Sequence of Data type of parameters
|
|
|
why is Method overloading is an example of Static Polymorphism. începe să înveți
|
|
because it happens at compile time
|
|
|
începe să înveți
|
|
When a data type of smaller size is promoted to the data type of bigger size than this is called type promotion, for example: byte data type can be promoted to short, a short data type can be promoted to int, long, double etc.
|
|
|
why is type promotion relevant to overloading? începe să înveți
|
|
it is very important to understand type promotion else you will think that the program will throw compilation error but in fact that program will run fine
|
|
|
what are bytes promotions? începe să înveți
|
|
|
|
|
what are shorts promotions? începe să înveți
|
|
|
|
|
what are ints promotions? începe să înveți
|
|
|
|
|
what are floats promotions? începe să înveți
|
|
|
|
|
what are longs promotions? începe să înveți
|
|
|
|
|