Posts

Showing posts from January, 2024

Exploring the Super Keyword and Casting Techniques

Image
Mastering Super keyword, Upcasting and Downcasting  Everything You Need to Know ☝ Super keyword The super keyword is used to call the constructor of a superclass from a subclass.  That is, it allows access to the members (methods, fields, constructors) of the parent class from within the subclass. Variables and methods can be called at any time via the super keyword. Unless one explicitly invokes the variables or methods of the super class using the super keyword, then nothing happens. Uses of super keyword Casting The term "casting" is commonly used to describe both implicit and explicit type conversions. Whether it's implicit casting or explicit casting, it's generally referred to as casting. The term “Type casting” specifically used when referring to casting objects from one class type to another, typically in the context of inheritance and polymorphism. There are two types of objects, parent object and child object. “Type casting” and “casting” refer to the sa...

The Art of Inheritance, Overriding and Method Overloading

Image
  The Art of Inheritance, Overriding and Method Overloading Inheritance👇 The process of connecting one class with another class is called Inheritance. Inheritance in Java is implemented using the "extends" keyword. Inheritance is a powerful mechanism in Java that promotes code reuse and supports polymorphism, enabling more flexible and maintainable code. Example-: Advantage of inheritance✊ 👉Inheritance allows classes to inherit fields and methods from a superclass.  👉 Inheritance supports polymorphism, which is the ability of objects of different classes to be treated as objects of a common superclass. 👉Subclasses can override methods inherited from the superclass to provide specialized implementations. 👉Inheritance allows for the extension of existing classes to create new classes with additional functionality. 👉Inheritance facilitates the organization of classes into hierarchies, which can represent real-world relationships or conceptual hierarchies. 👉 ...

Exploring the Power of Constructors

Image
  Exploring the Power of Constructors A constructor is a special method that is used to initialize objects. Constructor is automatically called when an object of that class is created. The constructor name same as the class name and they do not have a return type. Type of Constructors 👇 Parameterless 📌 🌟A parameterless constructor, often referred to as a default constructor, is a constructor in a class that takes no parameters.  🌟It is called automatically when an object of the class is instantiated without passing any arguments. Parameterized📌 🌟A parameterized constructor is a constructor in a class that takes one or more parameters.  🌟It allows you to initialize the object with specific values at the time of its creation.  🌟A parameterized constructor expects one or more arguments when it is called.  🌟The parameter list of the constructor works as parameter list and the parameter list of the object becomes an argument list. Article by-: Rasanjali...

A Comprehensive Guide to Classes, Variables, Keywords , Methods, Modifiers and the Main Method in Java

Image
  A Comprehensive Guide to Classes, Variables, Keywords , Methods, Modifiers and the Main Method in Java   Class A blueprint used to create an object is called a class. Various objects can be created related to one class. The limit of the class is only the class, the constructor of the class, and the main method.   The methods of the class do not belong to the limits of the class. If you want to know more about class read this blog post. https://kaushalyarasanjaliherath.blogspot.com/2023/12/unveiling-trinity-of-standards-objects.html?m=1 Variable  In Java, a variable is a storage location used to store information that can be changed during program execution.  That is, a variable is a named storage location where data is stored and can be referenced and manipulated in a program.  There are two types of variables in Java.  Variables are governed by the type of data they can hold. Static A static variable in Java is a class variable declared using ...