Study MaterialsInformatics Practices Class 12 Important Questions Chapter 6 Inheritance

Informatics Practices Class 12 Important Questions Chapter 6 Inheritance

Informatics Practices Class 12 Important Questions Chapter 6 Inheritance is part of Informatics Practices Class 12 Important Questions. Here we have given Informatics Practices Class 12 Important Questions Chapter 6 Inheritance.

Informatics Practices Class 12 Important Questions Chapter 6 Inheritance

1 Mark Questions

    Join Infinity Learn Regular Class Program!

    Download FREE PDFs, solved questions, Previous Year Papers, Quizzes, and Puzzles!

    +91

    Verify OTP Code (required)





    I agree to the terms and conditions and privacy policy.

    Question 1.
    Define the term inheritance’? (Delhi 2014)
    Answer:
    Inheritance is the ability to derive characteristics or features from an already existing entity, e.g. every child inherits properties from his/her parents. Similarly, in the programming world when the reusability of an existing class is required, the concept of inheritance is used. A class can inherits or derive its functionality from an already existing class as well as can have its own unique functionality and features.

    Question 2.
    What is the difference between superclass and subclass?
    Answer:
    A superclass is a class that is inherited whereas subclass is a class that does the inheritance, i.e. which derives the properties and behavior from the superclass.

    Question 3.
    How do you prevent a subclass from having access to a member of the superclass? (HOTS)
    Answer:
    When we want to prevent the access to a superclass member, declare that member as private.

    Question 4.
    Which type of inheritance lava supports?
    Answer:
    Java supports the following types of inheritance:

    • Single inheritance
    • Multilevel inheritance
    • Hierarchical inheritance

    Question 5.
    Can an object be a subclass of another object?
    Answer:
    No. An object cannot be a subclass of another object. Inheritance is possible only between classes.

    Question 6.
    Write the advantages of inheritance.
    Answer:
    The main advantages of inheritance are reusability of code and accessibility of variables and methods of the superclass by subclasses.

    Question 7.
    What restrictions are placed on method overloading?
    Answer:
    Two methods must have the same name but different argument list. However, the two methods may (or) may not have different return types.

    Question 8.
    What is the use of extends keyword?
    Answer:
    The extends keyword is used by the child class in order to inherit from parent class. And, also using the extends keyword an interface can inherit from another interface.

    2 Marks Questions

    Question 9.
    Can a derived class get access privilege for a private member of the base class? If yes, how? (HOTS)
    Answer:
    A derived class does not get direct access privilege for a private member of its base class, however, it always can access (indirectly), the private members of its base class through an inherited function that is accessing these members.

    Question 10.
    Define an abstract class.
    Answer:
    An abstract class is a class that contains at least one abstract method. An abstract class is a class that leaves one or more method implementations unspecified by declaring one or more methods abstract. An abstract method has no body (i.e. no implementation). A subclass is required to override the abstract method and provide an implementation. Hence, an abstract class is incomplete and cannot be instantiated, but can be used as a base class.

    Question 11.
    Give some points which are not accepted by inheritance in lava. (HOTS)
    Answer:

    • Private members of the superclass are not inherited by the subclass and can only be indirectly accessed.
    • Members that have default accessibility in the superclass are also not inherited by subclasses in other packages, as these members are only accessible by their simple names in subclasses within the same package as the superclass.
    • A subclass can extend only one superclass.

    Question 12.
    What are private, public and protected members of class?
    Answer:
    The private members are accessible only inside their own class, the public members are accessible in all the classes and protected members are accessible inside all the classes in their own package as well as in all subclasses of their class.

    Question 13.
    What do you mean by overloaded methods?
    Answer:
    Overloaded methods are methods with the same name but different signature by having either a different number of parameters or different types in the parameter list. e.g. ‘spinning’ a number may mean increase it, ‘spinning’ an image may mean rotate it by 90° degree. By defining a method for handling each type of parameter you control the desired effect.

    Question 14.
    Differentiate between an abstract class and interface.
    Answer:
    An abstract class is to be extended by another class but an interface is to be implemented in another class. An abstract class is created by the use of keyword abstract and an interface is created by the use of interface keyword.

    Question 15.
    Explain an interface.
    Answer:
    Interfaces are similar to abstract classes. In interface all methods are abstract and all properties are static final by default. Interface can be inherited (i.e. you can have a subinterface). As with classes the extends keyword is used for inheritance between interfaces. Java does not allow multiple inheritance for classes, i.e. a subclass being the extension of more than one superclass.

    An interface is used to tie elements of several classes together. Interfaces are also used to separate design from coding as class method headers are specified but not their bodies.

    Question 16.
    What do you mean by interface declaration?
    Answer:
    An interface declaration is nothing more than a specification to which some class that supports to implement the interface must confirm to in its implementation, i.e. a class that implements the interface must have defined implementations for each of the interface methods.

    Question 17.
    Write the difference between class inheritance and interface inheritance.
    Answer:
    1. Class Inheritance Creates a new class as an extension of another class, primarily for the purpose of code reuse, i.e. the derived class inherits the public methods and public data of the base class, Java only allows a class to have one immediate base class, i.e. single class inheritance.

    2. Interface Inheritance Creates a new class to implement the methods defined as part of an interface for the purpose of subtyping. That is a class that implements an interface “confirms to” (or is constrained by the type of) the interface. Java supports multiple interface inheritance.

    4 Marks Questions

    Question 18.
    What is the difference between protected and private members in inheritance? Explain it with the help of a program.
    Answer:
    The private members of a class are accessible only inside the class itself, in which it has been declared. Whereas, the protected members of a class are accessible inside the class and in all its subclasses.
    Below program shows the difference between them

    class Demo 
    {
    private int a; 
    protected int b; 
    publicvoid getdata( ) 
    {
    a=l 0 ; 
    b=20 ;
    }
    public int getnol( )
    {
    return a;
    }
    }
    class Addition extends Demo 
    {
    public int ad; 
    public void add( )
    {
    ad=getnol() + b;
    }
    public void getresult( ) 
    System.out.print1n(“Addition of two number=” + ad);
    }
    }
    public class MainDemo 
    {
    public static void main(String args[])
    {
    Addition A=new 
    Addition( ); 
    A.getdata( );
    A.add( );
    A.getresult( );
    }
    }

    Question 19.
    Explain the concept of method overloading in a programming language with an example. (HOTS)
    Answer:
    Method Overloading Creating more than one method with same name but with different signature, e.g. change in argument type or in argument list, these type of methods are said to be overloaded and the process is referred to as method overloading.
    E.g.,

    class Result 
    {
    float ar;
    public void area(float i)
    {
    ar=3.14*i*i;
    System.out.print!n(“Area of circle=”+ar);
    }
    public void area(int i)
    {
    ar=i*i;
    System.out.println(“Area of square=”+ar);
    }
    public void area(int 1,int b)
    {
    ar=l*b;
    System.out.println("Area of Rectangle=”+ar);
    }
    } public class MainResult 
    {
    public static void main(String args[])
    {
    Result r=new Result(); 
    r.area(2.5F); 
    r.area(15);. 
    r.area(18,20);
    } 
    }

    We hope the Informatics Practices Class 12 Important Questions Chapter 6 Inheritance help you. If you have any query regarding Informatics Practices Class 12 Important Questions Chapter 6 Inheritance, drop a comment below and we will get back to you at the earliest.

    Chat on WhatsApp

      Join Infinity Learn Regular Class Program!

      Sign up & Get instant access to FREE PDF's, solved questions, Previous Year Papers, Quizzes and Puzzles!

      +91

      Verify OTP Code (required)





      I agree to the terms and conditions and privacy policy.