Skip to content

Instantly share code, notes, and snippets.

@manjaykumardp
Last active November 16, 2022 09:19
Show Gist options
  • Save manjaykumardp/4f77ac1294e4143607323b6a5a3bbc11 to your computer and use it in GitHub Desktop.
Save manjaykumardp/4f77ac1294e4143607323b6a5a3bbc11 to your computer and use it in GitHub Desktop.
Use cases:
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();
}
}
@manjaykumardp
Copy link
Author

bro can you please also provide code in c++

thank you for your feedback i will try to provide code in c++

@manjaykumardp
Copy link
Author

I do have python code.

that's good

@DhananjayPorwal
Copy link

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()

@MUKESHKUMAR96084
Copy link

very nice approach

@kapilmaur9891
Copy link

Can you please provide cpp code??

@AkashTirkey
Copy link

please provide the cpp code.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment