0% found this document useful (0 votes)
2K views10 pages

Class-Xii Subject:-Computer Science: Chapter-12 Inheritance and Polymorphism

The document discusses inheritance and polymorphism in Java. It provides answers to 24 questions related to these concepts. Some key points covered are: inheritance allows a class to acquire properties of another class, polymorphism allows functions of the same name to be used for different purposes, base classes can be inherited from while derived classes inherit from base classes, and private, protected, and public visibility modes determine how members can be accessed by classes.

Uploaded by

Mayukhjha
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
2K views10 pages

Class-Xii Subject:-Computer Science: Chapter-12 Inheritance and Polymorphism

The document discusses inheritance and polymorphism in Java. It provides answers to 24 questions related to these concepts. Some key points covered are: inheritance allows a class to acquire properties of another class, polymorphism allows functions of the same name to be used for different purposes, base classes can be inherited from while derived classes inherit from base classes, and private, protected, and public visibility modes determine how members can be accessed by classes.

Uploaded by

Mayukhjha
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 10

CLASS-XII

SUBJECT:-COMPUTER SCIENCE
CHAPTER-12
INHERITANCE AND POLYMORPHISM
Book name: -UNDERSTANDING isc
computer science by APC
(COPY WORK)
PAGES:-(520-523)
EXERCISE 3:-ANSWER THE FOLLOWING
(PAGE 521)
Q1. What do you understand by inheritance?
Ans. The process by which one class acquires the properties of another class.
Q2. Explain ‘Polymorphism’ with a suitable example.
Ans. The process of declaring functions with the same name but for different purposes.
EXAMPLE:- void area(int l,int b)
void area(int r)
Q3. What do you mean by a base class?
Ans. A class which is getting inherited is known as base class.
Q4.Differentiate between a base class and derived class.
Ans. BASE CLASS:- A class which is getting inherited.
DERIVED CLASS:- A class which inherits the another class.
Q5.What do you mean by function overloading?
Ans. A process of defining functions with the same function names but with different
number and types of parameters.
Q6. What is polymorphism?
Ans. The process of declaring functions with the same name but for different purposes.
Q8. What is the need of polymorphism in Java
programming?
Ans. Polymorphism enables one entity to be used as
a general category for different types of actions. The
specific action is determined by the exact nature of
the situation.
Q9. Define the term ‘Function Signature’.
A function's signature includes the function's name
and the number, order and type of its
formal parameters.
Q10. What is the significance of using protected
declaration during inheritance? Show with the help
of an example.
Sometimes it may be necessary for a subclass to access a private member of a superclass.
If you make a private member public, then anyone can access that member. So, if a
member of a superclass needs to be (directly) accessed in a subclass and yet still prevent
its direct access outside the class, you must declare that member protected.
For example, let's imagine a series of classes to describe two kinds of shapes: rectangles
and triangles.
These two shapes have certain common properties height and a width (or base).

Q11. Describe the methods of accessing the data members and


member function of a class in the following cases:
(i) In the member function of the same class-private
(ii) In the member function of another class-public
(iii) In the member function of base class-public or protected
Q12.Base class by default, inherits another class.
Give your comment.
Ans. Except Object class, which has no superclass,
every class has one and only one direct superclass.In
the absence of any other explicit superclass,
every class is implicitly a subclass of Object class.
Q13. Explain the following:
In which circumstances a class is derived as public?
Ans. A class is derived as public when we want that
public and protected members of the base class act
as the public members of the derived class.
In which circumstances a class is declared as
private?
Ans. A class is derived as private when we want that
public and protected members of the base class act
as the private members of the derived class.
Q14. How can you access a private member of a base class?
Ans. A base class's private members are never accessible directly from a derived class,
but can be accessed through calls to the public and protected members of the base class.
Q15. In what way, the access specifiers of the base class have access control over derived
class? Explain with the help of an example.
The derived class can access all the non-private members of its base class. And thebase
class members that are not accessible to the member functions of derived classes should
be declared private in the base class. The access specifiers that are used are public,
private and protected.
Q16. Why is the main method so special in Java?
The main method or the driver method, acts as an entry point. The execution of your
program starts with main. You create objects in main method and call
class methods from main with the help of the object. In short, Java program without
themain method is similar to life without oxygen. That is why, the main method is so
special in Java.
Q17. What is encapsulation? What is its significance in Java programming?
Ans. Encapsulation in Java is a mechanism of wrapping the data (variables) and code
acting on the data (methods) together as a single unit.
The significance of encapsulation in java programming is: -
Data Hiding – It can provide the programmer to hide the inner classes and the user to
give access only to the desired codes. It allows the programmer to not allow the user to
know how variables and data store.
Q18. In what way a class enforces data hiding?
Ans. In encapsulation, the variables of a class will be hidden from
other classes, and can be accessed only through the methods of
their current class. Therefore, it is also known as data hiding.
To achieve encapsulation in Java −
i. Declare the variables of a class as private.
ii. Provide public setter and getter methods to modify and view
the variables values.
Q19. What are the types of visibility modes used in Java?
Ans. The types of visibility modes used in java are:-
Visible to the package, the default. No modifiers are needed.
Visible to the class only (private).
Visible to the world (public).
Visible to the package and all subclasses (protected).
Q20. How does a java program get affected, if data members are
declared as private?
Ans. When all data is declared as private, the data is only
accessible through the methods provided by the class.
Q21. Can a private member be accessed by:
A member of the same class? yes
A member of other class? yes(indirectly)
A function which is not a member function? No
Q22. What happens when a happening class derives
an accident class by using private visibility?
Ans. When using private inheritance, all public and
protected members of an accident class will
become private members in the happening class.
Only member functions of the happening class can
access them.
Q23. What do you understand by static data member?
Explain its application with the help of an example.
Ans. In Java, static members are those which belongs to the
class and you can access these members without
instantiating the class.
Example: -public class MyClass
{
public static int data = 20;
public static void main(String args[])
{
System.out.println(MyClass.data);
}
}
Q24. Show with the help of an example as how the
following base class can be derived in class bill to fullfill
the given requirement:

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy