Learn With Reshu is here to help you all to get new Technological ideas and knowledge. I will try to create blogs on all technical topics and new tricks and tips. please do like share and subscribe Learn with Reshu to encourage me more for creating good help to others.
Thanks,
Best Regards
#learnwithReshu
Advanced Java Programming Advanced Java Programming :- Introduction to advance java As most of us already know that if we want to make normal applications it can be easily built using core Java concepts. But, when it we need to develop web applications, advanced Java fundamentals, like JSP, Servlets, JDBC etc. needed, so to add capabilities and features of the application advance java is essential for developers. Through the motive of this blog is to explain about Advanced Java, I will be giving you a complete insight into the fundamental concepts of Advance Java. Figure - 1.2 If you want to see complete video on this please have a look the video below. Learn with Resh u Advanced Java Programming Course ...
Get link
Facebook
X
Pinterest
Email
Other Apps
Polymorphism in Java Method Overriding and Method OverLoading in Java
Get link
Facebook
X
Pinterest
Email
Other Apps
-
Polymorphism
in Java Method Overriding and Method OverLoading in Java
Java 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 Blog; Inheritance lets 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.
Polymorphism are two types
Method Overriding : It calls as compile time polymorphism or static or early binding.
Method Overloading: It calls as Runtime polymorphism or dynamic or late binding.
For example, think of a superclass called Animal that has a method called animalSound(). Subclasses of Animals could be Pigs, Cats, Dogs, Birds - And they also have their own implementation of an animal sound (the pig oinks, and the cat meows, etc.): This is a example of Method overriding in Polymorphism.
Example
classAnimal{publicvoidanimalSound(){System.out.println("The animal makes a sound");}}classPigextendsAnimal{publicvoidanimalSound(){System.out.println("The pig says: wee wee");}}classDogextendsAnimal{publicvoidanimalSound(){System.out.println("The dog says: bow wow");}}
Now we can create Pig and Dog objects and call the animalSound() method on both of them:
classAnimal{publicvoidanimalSound(){System.out.println("The animal makes a sound");}}classPigextendsAnimal{publicvoidanimalSound(){System.out.println("The pig says: wee wee");}}classDogextendsAnimal{publicvoidanimalSound(){System.out.println("The dog says: bow wow");}}classMyMainClass{publicstaticvoidmain(String[] args){Animal myAnimal =newAnimal();// Create a Animal objectAnimal myPig =newPig();// Create a Pig objectAnimal myDog =newDog();// Create a Dog object
myAnimal.animalSound();
myPig.animalSound();
myDog.animalSound();}}
Method Overriding
In Method Overriding the overridden method has same name but different arguments as number of arguments Sequence of arguments or type of arguments would be different.
In The example below the Class Adder has three add method with different arguments this is a example of method overriding.
package com.polymorphism.examples;
public class Adder {
void add(double a, int b) {
System.out.println(a+b);
}
void add(int b, double a) {
System.out.println(a+b);
System.out.println("Sequence changed");
}
void add(int a, int b) {
System.out.println("no arguments");
}
public static void main(String[] args) {
Adder test = new Adder();
test.add(4,7);
test.add(3.3, 7);
test.add(8 , 4.9 );
}
}
There are some Difference between Method Overriding And Method Overloading
Difference Between Method Overloading and Method Overriding
Example of Polymorphism
For Complete Explanation in Hindi Please visit My Youtube Channel
Complete Explanation on Method Overloading In Hindi
Complete Explanation on Method Overriding In Hindi
Running and Building Gradle with Different JDKs - Sip of Java If you are using Gradle as the build tool for your projects and want to work with the latest JDK releases or early-access builds, you might think you are stuck until Gradle supports those versions of the JDK, which might take a few months. However, that’s not the case, and we will explore in this article how to run Gradle with one JDK version while building and testing with a different JDK version. Managing Multiple JDKs When working with multiple JDKs, using a tool like SDKMan or Jenv (for macOS) is highly recommended. These tools enable you to easily manage and switch between your local JDKs. This article assumes that you have multiple JDKs installed on your system: one for running Gradle, and the other for executing the tasks in the build. Be sure that the JDK installed to run Gradle is supported by Gradle. As of the time of this article, the latest Gradle version is 7.6 which supports JDK 19. Configuring the Toolch...
LOOPS IN JAVA WITH EXAMPLE CODE In programming languages, loops are used to execute a set of instructions/functions repeatedly when some conditions become true. There are three types of loops in Java. for loop while loop do-while loop Java For Loop vs While Loop vs Do While Loop Java For Loop The Java for loop is used to iterate a part of the program several times. If the number of iteration is fixed, it is recommended to use for loop. There are three types of for loops in java . Simple For Loop For-each or Enhanced For Loop Labeled For Loop Example: 01. Simple For Loop //Java Program to demonstrate the example of for loop //which prints table of 1 public class ForExample { public static void main(String[] args) { //Code of Java for loop ...
Learn Complete OOPS Concepts in one Project In this Page i will give a example Code for covering all oops concepts in only one single project. Class Model Code Example Explanation:- Suppose there is a Organization which has many departments and many Employees Some Employees are Part of Some Departments So In this Code example What i have created is A Organization Class Which is having Many Employees so One Employee Class and Employee is a part of Departments so We have Created one Departments Class Now Organization, Department and Employee has some task to be done so for that i have created Interfaces for each one where i H...
Comments
Post a Comment
Please do not comment any spam link in the comment box