Tuesday , 27 June 2017
Home » Weekly Practice Question Class 12 » [Week 2] Weekly Important Practice Questions for ISC Computer Science

[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.

[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
  1. extends keyword is used for inheriting a class from another class.
  2. Using the extends keyword we can inherit only a single class.
  1. implements keyword is used for implementing an interface from another class.
  2. Using the implements keyword we can implement multiple interfaces.

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.

Check Also

Important Practice Questions for ICSE [Set 1]

Important practice questions for ICSE Computer Application students [Multiple Choice Questions and Output Questions)

2 comments

  1. Answers:

    1. The keyword extends specify the extension of another class(subclass) from the parent class and the extended sub-class inherits all the properties, methods and functions of the parent class.
    Whereas,whenever a class implements another class it no more remains a class rather it is called an interface.everything is not inherited in case of interface only the required method of the parent class is inherited.

    2. The only rule pertaining to Access Specifiers in Method Overriding is:

    That the subclass overridden method can have either same or stronger access than the parent class but not weaker access.

    3. Subclass can be prevented from having access to a member of a super class by using the access modifier private.Private makes a member accessible only from within its own class not the classes in the same package or to the subclass of the class.

    4. No,the constructors cannot be inherited as such by the subclass but the super-class’s constructor can be internally called by using the keyword super().

    5. For a sub class to explicitly call the constructor of it’s super class ,the keyword super(); is required.

    • Your answer for question 1 was not clear enough as it should be and you answered question 2 incorrectly. Rest your answers were good.

      Answers:

      1. Differentiate between the keywords – “extends” and “implements”.

      extends implements
      1. extends keyword is used for inheriting a class from another class.
      2. Using the extends keyword we can inherit only a single class.
      1. implements keyword is used for implementing an interface from another class.
      2. Using the implements keyword we can implement multiple interfaces.

      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. Required fields are marked *