Java Model Question Solution 2nd Sem

2nd sem New syallbus

Q.no 11

Q.no 12

 

Q.no 13

 

Q.no 14

 

Q.no 15

Group C

Q.No 17

 

Q.No 18

 

Q.No 19

 

Q.No 20

Group D

Q.No 21

OOP Principles Followed by Java:

  1. Encapsulation: Wrapping data (fields) and methods in a single unit (class).
  2. Abstraction: Hiding implementation details and exposing only essential features.
  3. Inheritance: Mechanism to acquire properties and behaviors of a parent class.
  4. Polymorphism: Ability to perform a single action in different ways (e.g., method overloading and overriding).

Restrictions of Static Methods:

  • Static methods belong to the class rather than an object.
  • They cannot access instance variables or instance methods directly.
  • They cannot use this or super keywords.
  • They can only call other static methods or use static variables.

Java Program Demonstrating Static Method:

Q.no 22

Definition of Inheritance:

Inheritance is a mechanism in object-oriented programming where one class (child/subclass) inherits properties and behaviors (fields and methods) from another class (parent/superclass).

Advantages of Inheritance:

  1. Code Reusability: Allows reuse of existing code.
  2. Extensibility: New features can be added without modifying existing code.
  3. Polymorphism: Enables dynamic method invocation.
  4. Reduced Redundancy: Avoids duplication of code.

Types of Inheritance in Java:

  1. Single Inheritance:
    • A subclass inherits from a single parent class.
    • Example:

Multilevel Inheritance:

A class inherits from another class, and that class inherits from another class.

 

Hierarchical Inheritance:

Multiple classes inherit from a single parent class.

 

Leave a Reply

Your email address will not be published. Required fields are marked *