“Überlastung von Java -Methoden” Code-Antworten

Überlastung von Java -Methoden

static int plusMethodInt(int x, int y) {
  return x + y;
}

static double plusMethodDouble(double x, double y) {
  return x + y;
}

public static void main(String[] args) {
  int myNum1 = plusMethodInt(8, 5);
  double myNum2 = plusMethodDouble(4.3, 6.26);
  System.out.println("int: " + myNum1);
  System.out.println("double: " + myNum2);
}
naly moslih

Methodenüberlastung in Java

public class Multi{ //Super class
public void multi(String name){ //String parameter
………………
}
}
 
Public class Multiplication extends Multi(){
Public void multi(){//No Parameter
………..
}
Public void multi(int x){ //integer parameter
 
}
Public static void main(String args[]){
Multiplication multiplication = new Multiplication();
multiplication.multi();
}
}
Outrageous Ostrich

Methodenüberschreibung in Java

public class Multi{ //Super class
public void multi(){
………………
}
}
 
Public class Multiplication extends Multi(){
Public void multi(){
………..
}
Public static void main(String args[]){
Multi multiplication = new Multiplication(); //Polimorphism is applied
multiplication.multi(); // It calls the Sub class add() method
}
}
Outrageous Ostrich

Java -Methode Überschreibung

class Animal {
   public void displayInfo() {
      System.out.println("I am an animal.");
   }
}

class Dog extends Animal {
   @Override
   public void displayInfo() {
      System.out.println("I am a dog.");
   }
}

class Main {
   public static void main(String[] args) {
      Dog d1 = new Dog();
      d1.displayInfo();
   }
}
SAMER SAEID

Ähnliche Antworten wie “Überlastung von Java -Methoden”

Durchsuchen Sie beliebte Code-Antworten nach Sprache

Durchsuchen Sie andere Codesprachen