[go: up one dir, main page]

0% found this document useful (0 votes)
11 views4 pages

Exp10oopm A36

The document outlines a student's practical assignment on inheritance in Java, detailing their code, observations, and conclusions. It explains the concept of inheritance, its types, and addresses questions about multiple inheritance, polymorphism, and the reasons Java programmers utilize inheritance. The student demonstrates an understanding of these concepts through their practical experience and responses to questions.

Uploaded by

taff270917
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)
11 views4 pages

Exp10oopm A36

The document outlines a student's practical assignment on inheritance in Java, detailing their code, observations, and conclusions. It explains the concept of inheritance, its types, and addresses questions about multiple inheritance, polymorphism, and the reasons Java programmers utilize inheritance. The student demonstrates an understanding of these concepts through their practical experience and responses to questions.

Uploaded by

taff270917
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/ 4

PART B

(PART B: TO BE COMPLETED BY STUDENTS)


(Students must submit the soft copy as per following segments within two hours of
the practical. The soft copy must be uploaded at the end of the practical)
Roll. No: 36 Name: Tanishka Gaikwad
Class: SE-A Batch: A2
Date of Experiment: 26/08/24 Date of Submission: 30/08/24
Grade:

B.1 Software Code written by student:


(Paste your code completed during the 2 hours of practical in the lab here)
B.2 Input and Output:

B.3 Observations and learning:


(Students are expected to comment on the output obtained with clear observations
and learning for each task/ sub part assigned)
Thus we have created a base class Student and then class Test which inherits from
Student and then a class Result that extends Test class.
And we have hence understood the concept of Inheritance.

B.4 Conclusion:
(Students must write the conclusion as per the attainment of individual outcome listed
above and learning/observation noted in section B.3)

Therefore we have become aware of Inheritance and it’s types and executed the source
code as above.
B.5 Question of Curiosity
(To be answered by student based on the practical performed and
learning/observations)
1. Why multiple Inheritance is not supported by Java?
[ANS]. Java does not support multiple inheritance with classes due
to several reasons, primarily to avoid complexity and ambiguity:
1. Diamond Problem: Ambiguity in method inheritance from
multiple classes.
2. Simplicity: Keeps the inheritance model straightforward.
3. Maintainability: Reduces complexity in class hierarchies.
4. Interface Mechanism: Provides a way to achieve multiple
inheritance through interfaces.

2. What is the difference between Polymorphism and Inheritance?


[ANS]. •Inheritance:
• Definition: A mechanism where one class (subclass)
inherits properties and behavior (methods) from another class
(superclass).
• Purpose: To enable code reuse and establish a hierarchical
relationship between classes.
• Example: A Dog class inheriting from an Animal class.
• Polymorphism:
• Definition: The ability of a single function or operator to
operate in different ways based on the type of input.
• Purpose: To allow methods to do different things based on
the object it is acting upon, enhancing flexibility and the ability to
extend code.

3. What are different types of Inheritance supported by Java?


[ANS]. Java supports the following types of inheritance:
1. Single Inheritance: A class (subclass) inherits from one
superclass. Example: `class Dog extends Animal`.
2. Multilevel Inheritance: A class inherits from a subclass, forming
a chain. Example: `class Dog extends Animal`, `class Bulldog
extends Dog`.
3. Hierarchical Inheritance: Multiple subclasses inherit from a
single superclass. Example: `class Dog extends Animal`, `class Cat
extends Animal`.
4. Multiple Inheritance (through interfaces): A class implements
multiple interfaces. Although Java does not support multiple
inheritance through classes, it supports multiple inheritance
through interfaces. Example: `class Hybrid implements Interface1,
Interface2`.
5. Interface Inheritance: Interfaces can extend other interfaces. A
subclass can implement multiple interfaces that extend other
interfaces. Example: `interface Animal`, `interface Mammal
extends Animal`, `class Dog implements Mammal`.

4. Why Inheritance is used by Java Programmers?

[ANS]. Java programmers use inheritance for several key reasons:

1. Code Reuse: Inheritance allows a new class (subclass) to reuse code


from an existing class (superclass), reducing redundancy and
promoting efficient code management.

2. Extensibility: It makes it easy to extend existing code. By creating


subclasses, programmers can add new features or modify existing
ones without altering the original code.

3. Maintainability: Changes in the superclass automatically propagate


to subclasses, making it easier to maintain and update code in a
centralized manner.

4. Hierarchy and Organization: Inheritance helps in organizing and


structuring code into a hierarchy, which mirrors real-world
relationships and makes the code more intuitive.

5. Polymorphism: Through inheritance, subclasses can override


methods of the superclass, enabling polymorphic behavior where
methods can act differently based on the object’s actual type.

You might also like