OBJECTS, INHERITANCE, AND INTERFACE
- SHASHANK GUNDA
- May 11, 2023
- 2 min read
Updated: May 16, 2023
We already studied what is Class and Packages. Now we will get to know about Object inheritance and interface the major concept of OOP( Object Oriented Programming ).
What is an Object?
Everything in real life is an object and possesses some characteristics like it can eat, run and sleep, colour, size, etc. Excited about how the objects can be used and created in programming, well we know that while creating a class we define some fields, methods, constructors, etc., simply class is the blueprint of an object.
Let's Recall the same and understand in-depth, Every object has its own state and behaviour. For Example, A Dog has a state like colour, breed, name, and behaviour like barking and eating.
Take a break and observe real-world objects in your area and try to identify their State and Behaviour. Have you done with the exercise, If yes that would be a great start for understanding object-oriented programming. It may be complex to understand real-world objects. For instance, Lamp has two possible states( on and off ) and two possible behaviours( turn on and turn off ), TV have some more possible states( on, off, current channel, and current volume ) and some more possible behaviours( turn on, turn off, change the channel, increase volume and decrease volume).
class Vehicle
{
//some fields
String vechicleModel;
String colour;
int price;
int noOfGares;
//some methods
void engineOn(){
}
int gareNo(){
}
}Every object stores the states in the form of fields and behaviours in the form of methods.
What is Inheritance?
When the term inheritance has listened you might go back to biology, True the concept was similar in programming. you can inherit the properties of one class from another, This enables the valuable feature of reusability within the code.
Inheritance is a fundamental concept in object-oriented programming that simplifies software development.
let's understand the topic in depth. Have you ever observed this thing, many objects around you often have some similar characteristics( i.e. state and behaviour ).
For instance, Imagine you are surrounded by various animals like cats, dogs, and birds. You may have noticed that many of them share similar behaviours like eating, sleeping, and running.
we can significantly reduce our workload instead of creating a separate class. Inheritance allows us to leverage existing code and behaviours, promoting code reuse and avoiding duplication. This approach simplifies development and enhances efficiency by building upon the foundation of common properties rather than starting from scratch.
Think why don't you inherit some properties from another object that shares similar characteristics, we can significantly reduce our workload instead of creating a separate class.
Inheritance allows us to leverage existing code and behaviours, promoting code reuse and avoiding duplication. This approach simplifies development and enhances efficiency by building upon the foundation of common properties rather than starting from scratch.


Comments