Java 18 - method overloading and constructor over loading

PHOTO EMBED

Sun Nov 26 2023 17:06:03 GMT+0000 (Coordinated Universal Time)

Saved by @Java

//Method Overloading 

classMotorBike 

{ 

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 LabTask18a 

{ 

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

 { 

MotorBike b=new MotorBike(); 

b.start(); 

b.start("Self"); 

 } 

}

//Constructor Overloading 

class LabTask18b 

{ 

 String lang; 

LabTask18b() 

 { 

this.lang="Java"; 

 } 

LabTask18b(String lang) 

 { 

this.lang=lang; 

 } 

public void getLang() 

 { 

System.out.println("Programming Langauage: "+this.lang); 

 } 

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

 { 

 LabTask18b obj1=new LabTask18b(); 

 LabTask18b obj2=new LabTask18b("C++"); 

obj1.getLang(); 

obj2.getLang(); 

 } 

}
content_copyCOPY