Last active
November 16, 2022 09:19
-
-
Save manjaykumardp/4f77ac1294e4143607323b6a5a3bbc11 to your computer and use it in GitHub Desktop.
Use cases:
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package data.structure.java; | |
class person{ | |
private String name; | |
private String noOfVehicle; | |
private String vehicle1; | |
private String Vehicle2; | |
void setPersonDetails(String newName,String noOfVehicle,String vehicle1,String vehicle2){ | |
this.name=newName; | |
this.noOfVehicle=noOfVehicle; | |
this.vehicle1=vehicle1; | |
this.Vehicle2=vehicle2; | |
} | |
void getPersonDetails(){ | |
System.out.println(name+" has "+noOfVehicle+",vehicle one is "+vehicle1+" and another is "+Vehicle2 ); | |
} | |
} | |
class vehicle { | |
protected String fuel; | |
protected String uses; | |
protected String operation; | |
static class hondaAccordCar extends vehicle{ | |
void sethondaAccordCar(String newfuel,String uses,String madein){ | |
this.fuel=newfuel; | |
this.uses= uses; | |
this.operation=madein; | |
} | |
void getHondaAccordCar(){ | |
System.out.println("Honda accord car runs on fuel called "+fuel); | |
System.out.println("Honda accord is "+uses+" and "+operation+" in India"); | |
} | |
} | |
static class DucatiBike extends vehicle{ | |
void setDucatiBike(String newFuel,String uses,String imported){ | |
this.fuel= newFuel; | |
this.uses=uses; | |
this.operation=imported; | |
} | |
void getDucatiBike(){ | |
System.out.println("Ducati runs on fuel called "+fuel); | |
System.out.println("Ducati is "+uses+" and "+operation+" vehicle"); | |
} | |
} | |
public static void main(String[] args) { | |
// creating object for person whose name is sourabh | |
person p = new person(); | |
p.setPersonDetails("Sourabh","two","honda accord car","Ducati Bike"); | |
p.getPersonDetails(); | |
// creating object forHonda accord car | |
hondaAccordCar h = new hondaAccordCar(); | |
h.sethondaAccordCar("diesel","new","made"); | |
h.getHondaAccordCar(); | |
// creatting object for Ducati Bike | |
DucatiBike d = new DucatiBike(); | |
d.setDucatiBike("petrol","used","imported"); | |
d.getDucatiBike(); | |
} | |
} |
bro can you please also provide code in c++
thank you for your feedback i will try to provide code in c++
I do have python code.
that's good
I do have python code.
that's good
take this python code and add it to your gist.
class Person:
def __init__(self):
self.name = ""
self.noOfVehicle = ""
self.vehicle1 = ""
self.vehicle2 = ""
def setPersonDetails(self, newName, noOfVehicle, vehicle1, vehicle2):
self.name = newName
self.noOfVehicle = noOfVehicle
self.vehicle1 = vehicle1
self.vehicle2 = vehicle2
def getPersonDetails(self):
print(self.name, "has", self.noOfVehicle, "vehicle one is",
self.vehicle1, "and another is", self.vehicle2)
class vehicle:
def __init__(self):
self.fuel = ""
self.uses = ""
self.operation = ""
class hondaAccordCar(vehicle):
def sethondaAccordCar(self, newfuel, uses, madein):
self.fuel = newfuel
self.uses = uses
self.operation = madein
def getHondaAccordCar(self):
print("Honda accord car runs on fuel called", self.fuel)
print("Honda accord is", self.uses, "and", self.operation, "in India")
class DucatiBike(vehicle):
def setDucatiBike(self, newFuel, uses, imported):
self.fuel = newFuel
self.uses = uses
self.operation = imported
def getDucatiBike(self):
print("Ducati runs on fuel called", self.fuel)
print("Ducati is", self.uses, "and", self.operation, "vehicle")
if __name__ == "__main__":
p = Person()
p.setPersonDetails("Sourabh", "two", "honda accord car", "Ducati Bike")
p.getPersonDetails()
h = hondaAccordCar()
h.sethondaAccordCar("diesel", "new", "made")
h.getHondaAccordCar()
d = DucatiBike()
d.setDucatiBike("petrol", "used", "imported")
d.getDucatiBike()
very nice approach
Can you please provide cpp code??
please provide the cpp code.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
I do have python code.