Posts

Showing posts from April, 2023

Introducing Java Abstraction Concept

Image
Abstraction (Abstract Class) "Abstract" keyword is used to keep a method that cannot be given specific code (Meaningless) in a Super Class created according to a certain situation. Since there are several sub classes, the Super Class sets a Meaningless Method to override. 1. To keep Meaningless Method 2. Only an Abstract Class Method can hold an Abstract Method. 3. Abstract Class can hold any Abstract and Non-Abstract method. 4. Object and Constructor cannot be created from an Abstract Class. 5. Subclasses can use Super Keyword and create Method. abstract class Vehicle {  abstract void drive();  abstract void Man;  void Man() {  system.out.println("Man");  } } class Car extends Vehicle {  void drive() {  // car driven code  } } class Bike extends Vehicle {  void drive() {  // bike driven code  } }

Introducing Java Polymorphism Concept

Image
Polymorphism Polymorphism means "many forms", and it occurs when we have many classes that are related to each other by inheritance. Like we specified in the previous chapter; Inheritance l ets us inherit attributes and methods from another class.   Polymorphism   uses those methods to perform different tasks. This allows us to perform a single action in different ways. After overriding a method of a Super Class in a Sub Class, Upcasting and running the Sub Class Method through the Super Class Reference. class Biscuit extends Products {   void store() {     //store code   } } class Cake extends Products {   void store() {     //store code   } } class Chocolate extends Products {   void store() {     //store code   } } class SystemRun { psvm (String[]args) { Biscuit b = new Biscuit(); Cake c = new Cake(); Chocolate cl = new Chocolate(); 1.b.store(); 2.c.store(); 3.cl.store();   } } GitHub Projects

Introducing Java Upcasting And Downcasting Concepts

Image
  Upcasting And Downcasting Upcasting Upcasting  is a type of object typecasting in which a  child object  is typecasted to a  parent class object . By using the Upcasting, we can easily access the variables and methods of the parent class to the child class. Here, we don't access all the variables and the method. We access only some specified variables and methods of the child class.  Upcasting  is also known as  Generalization  and  Widening. In Casting, it is not possible to access big data from small data. But it is possible to access small data from big data. Putting something in the Super Class (Object, Variable, Method) in the Sub Class (Object, Variable, Method) is called "Upcasting". class A { } class B extends A { } class Test { A a = new A(); B b = new B(); b = a; a = b; } In Upcasting, what is simply done is to give a Sub Class Object to the Super Class Variable. Downcasting Turning the Sub Class Object cast into a Super Class Variable back into a Sub Class Va