DAY 22 & 23: Understanding of Encapsulation and Inheritance.

Encapsulation in getters and setters methods Encapsulation is achieved by declaring class attributes as private and providing public methods (getters and setters) to access and modify these attributes. This way, the internal state of an object is hidden from outside classes, and access to it is controlled. Types of programming 1.Functional programing 2.Modular programing 3.procedure oriented programing 4.object oriented programing What is return? Return means value not variable The return keyword in Java is used to exit from a method and optionally pass back a value to the method caller. It serves as a control flow statement that terminates the execution of the method in which it appears. What is final keyword In Java, the final keyword acts as a non-access modifier, primarily used to ensure immutability and prevent inheritance. It can be applied to variables, methods, and classes, making them unchangeable after initialization, preventing overridden methods, and stopping inheritance of classes, respectively. A final class cannot extended to create a subclass. All methods in a final class are implicitly final . Class String is an example of a final class. What is inheritance Java Inheritance is a fundamental concept in object-oriented programming that allows a new class to inherit properties and behaviors (fields and methods) from an existing class. This promotes code reusability and establishes a hierarchical relationship between classes. Why inheritance needed Inheritance in object-oriented programming is crucial for code reusability, reducing redundancy, and promoting a structured approach to software development. It allows new classes to inherit properties and behaviors from existing classes, avoiding the need to rewrite the same code multiple times. when should i go for inheritance in java In Java, inheritance should be used when there's a true "is-a" relationship between classes. This means a subclass should extend a superclass only if objects of the subclass are considered to be a specialized type of the superclass. For example, a Car "is-a" Vehicle, so Car should inherit from Vehicle

Apr 13, 2025 - 04:17
 0
DAY 22 & 23: Understanding of Encapsulation and Inheritance.

Encapsulation in getters and setters methods

Encapsulation is achieved by declaring class attributes as private and providing public methods (getters and setters) to access and modify these attributes. This way, the internal state of an object is hidden from outside classes, and access to it is controlled.

Types of programming
1.Functional programing
2.Modular programing
3.procedure oriented programing
4.object oriented programing

What is return?
Return means value not variable
The return keyword in Java is used to exit from a method and optionally pass back a value to the method caller. It serves as a control flow statement that terminates the execution of the method in which it appears.

What is final keyword
In Java, the final keyword acts as a non-access modifier, primarily used to ensure immutability and prevent inheritance. It can be applied to variables, methods, and classes, making them unchangeable after initialization, preventing overridden methods, and stopping inheritance of classes, respectively.

A final class cannot extended to create a subclass. All methods in a final class are implicitly final . Class String is an example of a final class.

What is inheritance

Java Inheritance is a fundamental concept in object-oriented programming that allows a new class to inherit properties and behaviors (fields and methods) from an existing class. This promotes code reusability and establishes a hierarchical relationship between classes.

Why inheritance needed
Inheritance in object-oriented programming is crucial for code reusability, reducing redundancy, and promoting a structured approach to software development. It allows new classes to inherit properties and behaviors from existing classes, avoiding the need to rewrite the same code multiple times.

when should i go for inheritance in java

In Java, inheritance should be used when there's a true "is-a" relationship between classes. This means a subclass should extend a superclass only if objects of the subclass are considered to be a specialized type of the superclass. For example, a Car "is-a" Vehicle, so Car should inherit from Vehicle