[Week 2] Weekly Important Practice Questions for ISC Computer Science
This week we have a few short questions on the topic of Inheritance for the ISC students preparing for their 2013 Computer Science Examination.
This week we have a few short questions on the topic of Inheritance for the ISC students preparing for their 2013 Computer Science Examination.
[To know more about these weekly practice questions, Click Here]
You need to answer the given questions, and reply it as comments by filling the "Leave a Reply" section below this post.
The correct answers will be posted next week.
Questions:
1. Differentiate between the keywords - "extends" and "implements".
2. What is the rule pertaining to Access Specifiers in Method Overriding?
3. How do you prevent a sub class from having access to a member of a super class?
4. Are the constructors of the super class inherited automatically (implicitly) by the sub class?
5. What is the condition for a sub class to explicitly call the constructor of it's super class?
Answers:
1. Differentiate between the keywords – “extends” and “implements”.
| extends | implements |
|---|---|
|
|
2. What is the rule pertaining to Access Specifiers in Method Overriding?
The rule pertaining to Access Specifiers in Method Overriding is:
The access specifier of the overriding method in the child class cannot have an access specifier which is more restrictive than the method in the parent class.
The child class overriding method can either have an access specifier which is equal or less restrictive than that of the parent class method.
Remember that the chain of access specifier is as follows: private -> default -> protected -> public
3. How do you prevent a sub class from having access to a member of a super class?
To prevent a subclass from having access to a superclass member, we declare that member as private.
4. Are the constructors of the super class inherited automatically (implicitly) by the sub class?
No, when a class is inherited, all its members are inherited except the constructor and the members declared private.
5. What is the condition for a sub class to explicitly call the constructor of it’s super class?
In order to explicitly call the constructor of the super class from the sub class, we use the keyword super( ) which should be the first statement in the sub class constructor.
Leave a Reply
Your email address will not be published. Comments are reviewed before appearing publicly.