Diagnostic Quiz
Problems
Q2. Overloading
The only requirement for overloading is that the method should have the same name but different method signature. (The return type doesn't matter)
Q3. Dynamic Binding
This question teaches us that the dynamic binding, which is covered in Method Invocation, is only applied to instance methods. Class methods only take the first stage, which is During Compile Time, and the method found after the compile-time will be executed directly during the run-time.
Q5. Narrowing Type Conversion
Consider the following code,
S s;
T t;
s = (S) t; // Line AIf, the RTT of t is not a subtype of , then a run-time error will be generated.
If, the CTT of t is not a subtype of , then a compile-time error will be generated.
Q11. Liskov Substitution Principle
When dealing with question regarding whether an inheritance violates LSP or not. Always use the test case method, which is check whether the test cases that pass in the parent class can all pass in the derived class.
Tips
We cannot do type casting between two types which has no subtype relationship. Otherwise, a compile-time error will be generated.
In the overloading methods, the return type doesn't matter.
When dealing with question regarding whether an inheritance violates LSP or not. Always use the test case method, which is check whether the test cases that pass in the parent class can all pass in the derived class.
Last updated