Posts

What Is an Interface?

An interface is a special type in programming that only declares what methods a class should have — not how those methods work. Think of it as: A toy blueprint — shows what parts the toy must have, but not the colors or materials. A remote control — has buttons (methods) you can press, but it doesn’t say what happens inside the TV. A promise/contract — “If you say you implement me, you must give me all these methods.” Why? Interfaces help us write flexible code where different classes can be used in the same way, even if they work differently inside. How Interfaces Differ from Classes and Abstract Classes Example 1 — Single Interface Implemented by a Class interface Flyable { void fly(); } class Bird implements Flyable { public void fly() { System.out.println("Bird is flying"); } } public class Main { public static void main(String[] args) { Bird b = new Bird(); b.fly(); } } ...

Inheritance [ class – abstract class (extends) ]

Image
First let’s understand what is an abstract class is. So, an abstract class is like a house that haven’t been fully developed yet, so the house can have some completed parts and also can have incomplete parts. As same as this the abstract class can have concrete methods as well as abstract methods which doesn’t have method body. When creating an abstract method there are few things that we need to consider: If any class contains any abstract method, that class needs to be marked as abstract using  abstract keyword. abstract methods cannot contain static keyword. In other words, static & abstract  keyword cannot be in the same method. There are two ways that an abstract class can be extended by a child class:                a.     extend to a concrete class: when extend happens between concrete class and an abstract class the abstract methods available within the abstract class needs to be override. It is a must. Th...

OOPC - Inheritance (class – class)

Image
In everyday speech, inheritance means receiving assets, property, or characteristics from someone else, typically from a family member (such as a parent). The inheritor (such as a child) can use these as they are or modify them as needed. For example, imagine a child inherits a car from a parent. The child can use the car as it was inherited or modify its features as needed. However, once the car has been modified, it is no longer possible to revert to the exact original state of the car. In programming, when we modify inherited features and behaviors, the original structure remains unchanged. We can always access the original version of the inherited class without affecting its original state. This concept is analogous to inheritance in Object-Oriented Programming (OOP). In Java, inheritance can occur in several scenarios: class – class (extends) class – abstract class (extends) class – interface (implements) abstract class – interface (implements) interface – interface (extends) more...

OOP

Image
OOP Object Oriented Programming is not a completely new concept since it has been around since like 1960s. the earliest implementation of the concept was using Simula programming language at around 1967. With the time, OOP became an essential part of programming since it gives lots of advantages compared to the previously available concepts like Procedural Programming and Structured Programming. OOP provides ways to simulation lots of real-world situations like relationships, entities, inheritance, so.. its quite interesting to understand how this works and how can we get out hands on this. OOPC One of the key thing we need to understand is OOPC (Object Oriented Programming Concepts). These concepts provides ways to interact with components in the OOP. These concepts includes: Inheritance Polymorphism Encapsulation Abstraction Overloading Overriding From next article, let's look into each one of these concepts with Java Programing Language examples.