Java 17- method overloading and overriding

PHOTO EMBED

Sun Nov 26 2023 17:04:48 GMT+0000 (Coordinated Universal Time)

Saved by @Java

//Method Overloading 

classMotor Bike 

{ 

private String startMethod = "Kick"; 

public void start() 

 { 

System.out.println(startMethod+" starƟng...");

 } 

public void start(String method) 

 { 

this.startMethod = method; 

System.out.println(startMethod+" starƟng...");

 } 

} 

public class LabTask17a 

{ 

public staƟc void main(String args[])

 { 

MotorBike b=new MotorBike(); 

b.start(); 

b.start("Self"); 

 } 

}
//Method Overriding 

classMotor Bike 

{ 

public void start() 

 { 

System.out.println("Using kick paddle to start..."); 

 } 

} 

classSelfStartMotorBike extends MotorBike 

{ 

public void start() 

 { 

System.out.println("Using self start buƩon to start...");

 } 

} 

public class LabTask17b 

{ 

public staƟc void main(String args[])

 { 

SelfStartMotorBike b=new SelfStartMotorBike(); 

b.start(); 

 } 

}
content_copyCOPY