Bienvenida e Introducción

1

¿Por qué aprender Programación Orientada a Objetos?

2

¿Qué resuelve la Programación Orientada a Objetos?

3

Paradigma Orientado a Objetos

4

Lenguajes Orientados a Objetos

5

Instalando Visual Studio Code

6

Diagramas de Modelado

7

Qué es UML

Orientación a Objetos

8

Objetos

9

Abstracción y Clases

10

Modularidad

11

Analizando Uber en Objetos

12

Reto 1: identificando objetos

Programación Orientada a Objetos. Análisis

13

Clases en UML y su sintaxis en código

14

Modelando nuestros objetos Uber

15

¿Qué es la herencia?

16

Aplicando Herencia a nuestro proyecto Uber

17

Reto 2: analicemos un problema

Clases, Objetos y Método Constructor

18

Creando nuestras carpetas iniciales para el curso

19

Definiendo clases en Java y Python

20

Definiendo Clases en JavaScript

21

Objetos, método constructor y su sintaxis en código

22

Objetos. Dando vida a nuestras clases en Java y Python

23

Declarando un Método Constructor en Java y JavaScript

24

JavaScript orientado a objetos, lo más nuevo

25

Declarando un método constructor en Python

Herencia

26

Aplicando herencia en lenguaje Java y PHP

27

Solución del reto de herencia en PHP

28

Aplicando herencia en lenguaje Python y JavaScript

29

Otros tipos de Herencia

30

Reto 4

Encapsulamiento

31

Encapsulamiento

32

Encapsulando atributos en Java

Polimorfismo

33

Generando polimorfismo en Java

34

Generando polimorfismo en PHP

Cierre del curso

35

El Diagrama UML de Uber

36

Conclusiones

37

Bonus: Qué es la Programación Orientada a Objetos

Curso de Programación Orientada a Objetos: POO

Curso de Programación Orientada a Objetos: POO

Anahí Salgado Díaz de la Vega

Anahí Salgado Díaz de la Vega

Reto 4

30/37

Lectura

Nos queda la Jerarquía Account pendiente.

Tomando como referencia nuestros diagramas. Plásmala en tu lenguaje de programación favorito.
Compártenos tus resultados.

1CBC2F61-08EB-4F0E-AE72-E13356C7E0EE.png

Aportes 453

Preguntas 9

Ordenar por:

¿Quieres ver más aportes, preguntas y respuestas de la comunidad? Crea una cuenta o inicia sesión.

Java:

Python:

Javascript:

Php:

Yo lo hice en Python

class Account:
    id = int
    name = str
    document = str
    email = str
    password = str

    def __init__(self, name, document):
        self.name = name
        self.document = document
from account import Account

class User(Account):
    def __init__(self, name, document, email, password):
        super.__init__(name, document, email, password)
from account import Account

class Driver(Account):
    def __init__(self, name, document, email, password):
        super.__init__(name, document, email, password)

Mis resultados en JavaScript:

Account.js

class Account {

    constructor(name, document, email, password) {
        this.id;
        this.name = name;
        this.document = document;
        this.email = email;
        this.password = password;
    }

    printDataAccount() {
        console.log("The name: " + this.name);
        console.log("The document: " + this.document);
        console.log("The email: " + this.email);
        console.log("The password: " + this.password);
    }

}

User.js

class User extends Account {

    constructor(name, document, email, password) {
        super(name, document, email, password)
    }

}

Driver.js

class Driver extends Account {

    constructor(name, document, email, password) {
        super(name, document, email, password)
    }

}

index.js

var user = new User("Jose Ramirez", "INE001","[email protected]", "mypass");
user.printDataAccount();

index.html

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>Herencia JS</title>
</head>
<body>
    <script src="Account.js"></script>
    <script src="User.js"></script>      
    <script src="index.js"></script>
    
</body>
</html>

Resultados en consola:

Hecho en Java

Account

public class Account {
    Integer id;
    String name;
    String document;
    String email;
    String password;

    public Account(String name, String document, String email, String password){
        this.name = name;
        this.document = document;
        this.email = email;
        this.password = password;
    }
}

Driver

public class Driver extends Account{
    
    public Driver(String name, String document, String email, String password){
        super(name, document, email, password);
    }
}

User

public class User extends Account{
    
    public User(String name, String document, String email, String password){
        super(name, document, email, password);
    }
}

🐱‍💻 Plasmando la solución en lenguaje Dart.

class Account {
  int id;
  String name;
  String document;
  String email;
  String password;

  Account({this.name, this.document});

  void printData(){
      print('Name: $name Document: $document');
  }
}
import 'account.dart';

class User extends Account{
  User({name, document}):super(name: name, document: document);
}
import 'account.dart';

class Driver extends Account{
  Driver({name, document}):super(name: name, document: document);
}
import 'user.dart';
import 'driver.dart';

void main() {
  User user = User(name: 'Andres Herrera', document: 'QWE234');
  user.printData();

  Driver driver = Driver(name: 'Andrea Ferran', document: 'ANDA765');
  driver.printData();
}

En Python creería que debe ser así.

Clase Account

class Account:
    """
    account class
    """
    id          = int
    name        = str
    document    = str
    email       = str
    password    = str
    
    def __init__(self,id,name,document,email,password):
        self.id         = id
        self.name       = name
        self.document   = document
        self.email      = email
        self.password   = password

Clase User

from account.py import Account 
class User(Account):
    """
    User Class
    """
    def __init__(self,id,name,document,email,password):
        super().__init__(id,name,document,email,password)

Clase Driver

from account.py import Account 
class Driver(Account):
    """
    Driver Class
    """
    def __init__(self,id,name,document,email,password):
        super().__init__(id,name,document,email,password)

Me esto dando cuenta que todos están haciendo los ejemplos en el lenguaje de preferencia, yo los he hecho en todos 😓😫

Python :

//main.py

from car import Car
from payment import Payment
from account import Account

if __name__ == "__main__":
    print("Hola Mundo")
    car = Car()
    car.license = "AMS234"
    car.driver = "Andres Herrera"
    print(vars(car))

    car2 = Car()
    car2.license = "QWE567"
    car2.driver = "Matha"
    print(vars(car2))

    paypal = Payment()
    paypal.id = 21231
    paypal.email = "[email protected]"
    print(vars(paypal))

    user = Account() 
    user.id = 21222
    user.name = "Sherk"
    user.document = "S21K"
    user.email = "[email protected]"
    user.password = "YoMeOp0ngo"
    print(vars(user))

//account.py
class Account:
    id          = int
    name        = str
    document    = str
    email       = str
    password    = str

//user.py

from account import Account

class User(Account):
    def __init__ (self, id, name, document, email, password):
        super.__init__(id, name, document, email, password)

//driver.py

from account import Account

class Driver(Account):
    def __init__ (self, id, name, document, email, password):
        super.__init__(id, name, document, email, password)


Aquí les muestro como seria en Ruby 😉

  class Account
    attr_accessor :id, :name, :document, :email, :password
  
    def initialize(id, name, document, email, password)
      self.id = id
      self.name = name
      self.document = document
      self.email = email
      self.password = password
    end
  end
  
  class Driver < Account
    def call_taxi
      puts "Llamaste al conductor: #{self.name} con documento #{self.document}"
    end
  end
  
  class User < Account
    def fullname
      puts "El nombre de este usuario es: " + self.name
    end
  end
  
  d = Driver.new(1, 'Ferdy', '98761', '[email protected]', 'pass$$')
  d.call_taxi # Llamaste al conductor: Ferdy con documento 98761       
  d.name # Ferdy

Python

]

En Python:


En Ruby:

account.rb

class Account
  attr_accessor :name, :document, :email, :password
  
  def initialize(name, document, email, password)
    @name = name
    @document = document
    @email = email
    @password = password
  end

  def print_data_account
    puts "Name: #{@name}"
    puts "Document: #{@document }"
    puts "Email: #{@email}"
    # Esto es para imprimir ****** en lugar del password ;-)
    puts "Password: #{'*' * @password.length}"
  end
end

user.rb

class User < Account
end

driver.rb

class Driver < Account
end

app.rb

user= User.new("Diego Camacho", "ID001","[email protected]", "password")

user.print_data_account

# Name: Diego Camacho
# Document: ID001
# Email: dcamacho@gmail.com
# Password: ********

Python:

User:

from account import Account

class User(Account):
    def __init__(self, name, document):
        super.__init__(name, document)

Driver:

from account import Account

class Driver(Account):

    driverLicense = str

    def __init__(self, name, document, driverLicense):
        super.__init__(name, document)
        self.driverLicense = driverLicense

Java

public class Account {
  Integer id;
  String name;
  String document;
  String email;
  String password;

  public Account(String name, String document) {
    this.name = name;
    this.document = document;
  }

  public Account(String name, String document, String email, String password) {
    this.name = name;
    this.document = document;
    this.email = email;
    this.password = password;
  }

  public void printData() {
    System.out.println("Name: " + this.name);
    System.out.println("Document: " + this.document);
    System.out.println("E-mail: " + this.email);
  }
}
public class User extends Account {

  public User(String name, String document, String email, String password) {
    super(name, document, email, password);
  }

}
public class Driver extends Account {
  public String licenseNumber;

  public Driver(String licenseNumber, String name, String document, String email, String password) {
    super(name, document, email, password);
    this.licenseNumber = licenseNumber;
  }

User.py

from account import Account

class User(Account):

    def __init__(self, id, name, document, email, password):
        super.__init__(id, name, document, email, password)

Driver.py

from account import Account

class Driver(Account):

    def __init__(self, id, name, document, email, password):
        super.__init__(id, name, document, email, password)

Esta es mi clase base:

class BaseClass:
    def __init__(self, id_: int):
        self.id_ = id_

El id es declarado como id_ porque id es una function reservada en Python.

Todas las demás clases extiended la BaseClass

class Account(BaseClass):
    def __init__(self, id_: int, name: str, email: str, password: str):
        super().__init__(id_)

        self.name = name
        self.email = email
        self.password = password

    def __str__(self) -> str:
        return f'{self.name}, email: {self.email}'

En este caso, estamos creando un constructor con los datos pertinentes. El __str__ significa que cada vez que imprimimos un objeto Account, retorna el nombre y el email.


class Driver(Account):
    pass

class Passenger(Account):
    pass

Ya que el ID lo da la clase Account, no es necesario que las subclases Client y Driver tengan un ID. Las subclases pueden, por el momento, no tener atributos propios y solo usar los de la clase padre.

// java

class Client extends Account {
  public Client(String name, String document) {
    super(name, document);
  }
}

class Driver extends Account {
  public Driver(String name, String document) {
    super(name, document);
  }
}
# python (no olvidar importar la clase Account)

class Client(Account):
    def __init__(self, name, document):
        super().__init__(name, document)

class Driver(Account):
    def __init__(self, name, document):
        super().__init__(name, document)
// javascript

class Client extends Account {
  constructor(name, document) {
    super(name, document);
  }
}

class Driver extends Account {
  constructor(name, document) {
    super(name, document);
  }
}

JAVASCRIPT

  • Class Account
class Account
{
    constructor(name, document)
    {
        this.name = name;
        this.document = document;
        
        this.id;
        this.email;
        this.password;
    }

    setID(id) {
        this.id = id;
    }

    printAllAccountData() {
        console.log("ID: ", this.id);
        console.log("name: ", this.name);
        console.log("document: ", this.document);
    }

    printPublicAccountData() {
        console.log(this.name);
        console.log(this.document);
        console.log(this.email);
    }

    printPrivateAccountData() {
        console.log(this.id);
        console.log(this.password);
    }
}
  • Class User
class User extends Account
{
    constructor(account, email, pswd)
    {
        super(account, email, pswd);

        this.account = account;
        this.email = email;
        this.password = pswd;

    }

    printAllUserData() {
        console.log("----User Data----\r\n");
        this.account.printAllAccountData();
        console.log("email:\t", this.email);
        console.log("pswd:\t", this.password);
    }
}
  • Class Driver
class Driver extends Account
{
    constructor(account, email, pswd)
    {
        super(account);
        
        this.account = account;
        this.email = email;
        this.password = pswd;
    }

    printAllDriverData()
    {
        console.log("----Driver Data----\r\n");
        this.account.printAllAccountData();
        console.log("email:\t", this.email);
        console.log("pswd:\t", this.password);
    }

}
  • index.js
var Acc1 = new Account("Acc1", "30333444");
Acc1.setID("1");
var driver1 = new Driver(Acc1, "[email protected]", "pswd1")
driver1.printAllDriverData();

var Acc2 = new Account("Acc2", "30333555");
Acc2.setID("2");
var user1 = new User(Acc2, "[email protected]", "pswd2");
user1.printAllUserData();
  • Output
----Driver Data----
ID:  1
name:  Acc1
document:  30333444
email:	 acc1@gmail.com
pswd: 	 pswd1
----User Data----
ID:  2
name:  Acc2
document:  30333555
email:	 acc2@gmail.com
pswd :	 pswd2

Driver

User

main

account

Python

account. py

class Account: 
    id = int
    name = str
    document = str
    email = str 
    password = str

    def __init__(self, name, document):
        self.name = name
        self.document = document

Driver. py

from account import Account

class Driver(Account):
    email = str
    password = str

    def __init__(self, name, document, email, password):
        super().__init__(name, document)
        self.email = email
        self.password = password

User. py

from account import Account

class User(Account):
    email = str
    password = str

    def __init__(self, name, document, email, password):
        super().__init__(name, document)
        self.email = email
        self.password = password

PHP:

<?php
require_once('Account.php');

class AccountUser extends Account{
  public function __construct($name, $document, $email, $password){
    parent::__construct($name, $document);
    $this->email = $email;
    $this->password = $password;
  }
}
?>




<?php
require_once('Account.php');

class AccountDriver extends Account{
  public function __construct($name, $document, $email, $password){
    parent::__construct($name, $document);
    $this->email = $email;
    $this->password = $password;
  }
}
?>

23. Mis apuntes sobre: “Reto 4”

Les comparto la implementación del reto en mi lenguaje favorito por el momento, Javascript:

En primer lugar agregué una función para que imprima los datos a la clase Account:
-1.Account.js

class Account{
    constructor(name, document){
        this.id;
        this.name = name;
        this.document = document;
        this.email;
        this.password;
    }
    printDataAccount(){
        console.log(this.name);
        console.log(this.document);
    }
}

‘
’
-2.User.js

class User extends Account{
    constructor(name, document){
        super(name, document)
    }
}

‘
’
-3.Driver.js

class Driver extends Account{
    constructor(name, document){
        super(name, document)
    }
}

‘
’

User.php

<?php

require_once('Account.php');

class User extends Account {
  public function __construct($name, $document) {
    $this->name = $name;
    $this->document = $document;
  }
}

Driver.php

<?php

require_once('Account.php');

class Driver extends Account {
  public function __construct($name, $document) {
    $this->name = $name;
    $this->document = $document;
  }
}


Así de Fácil! 😃

User

public class User extends Account {
    
    public User(String name, String document) {
        super(name, document);
    }
}

Driver

public class Driver extends Account {
    
    public Driver(String name, String document) {
        super(name, document);
    }
}

En mi caso PHP:

Account.php

<?php
class Account {
    public $id;
    public $name;
    public $document;
    public $email;
    public $password;

    public function __construct($name, $document){
        $this->name = $name;
        $this->document = $document;
    }
}

User.php

<?php

require_once('Account.php');

class User extends Account{

    public function __construct($name, $document){
        parent::__construct($name, $document);
    }
    
}

Diver.php

<?php

require_once('Account.php');

class Driver extends Account{

    public function __construct($name, $document){
        parent::__construct($name, $document);
    }
}

JAVA

  • Account
class Account {
    Integer id;
    String name;
    String document;
    String email;
    String password;

    public Account(String name, String document) {
        this.name = name;
        this.document = document;
    }
}
  • User
class User extends Account {
    public User(String name, String document) {
        super(name, document);
    }
}
  • Driver
class Driver extends Account {
    public Driver(String name, String document) {
        super(name, document);
    }
}

JAVASCRIPT

  • Account
class Account {
    constructor(name, document) {
        this.id;
        this.name = name;
        this.document = document;
        this.email;
        this.password;
    }
}
  • User
class User extends Account {
    constructor(name, document) {
        super(name, document)
    }
}
  • Driver
class Driver extends Account {
    constructor(name, document) {
        super(name, document)
    }
}

PHP

  • Account
<?php
class Account {
    public $id;
    public $name;
    public $document;
    public $email;
    public $password;

    public function __construct($name, $document){
        $this->name = $name;
        $this->document = $document;
    }
}
?>
  • User
<?php

require_once('account.php');

class User extends Account {
    public function __construct($name, $document){
        parent::__construct($name, $document);
    }
}
?>
  • Driver
<?php

require_once('account.php');

class Driver extends Account {
    public function __construct($name, $document){
        parent::__construct($name, $document);
    }
}
?>

PYTHON

  • Account
class Account:
    id          = int
    name        = str
    document    = str
    email       = str
    password    = str

    def __init__(self, name, document):
        self.name       = name
        self.document   = document
  • User
from account import Account

class User(Account):
    def __init__(self, name, document):
        super().__init__(name, document)
  • Driver
from account import Account

class Driver(Account):
    def __init__(self, name, document):
        super().__init__(name, document)
class User extends Account{
    public User(String name,String document){
        super(name, document);
    }
}

class Driver extends Account{
    public Driver(String name,String document){
        super(name, document);
    }
}```
class Driver extends Account
{
    public Driver(String name, String document){
        super(name, document);

    }
}```



class User extends Account
{
public User(String name, String document){
super(name, document);

}

}```

CODIGO en Account.php

<?php
  
  class Account{
    public $id;
    public $name;
    public $document;
    public $email;
    public $password;
  
  public function __construct($name, $document, $email){
    $this->name = $name;
    $this->document = $document;
    $this->email = $email;
  }
  
  public function showDataUser(){
      echo "<h3>Informacion de Usuario:</h3>";
      echo "<br/> Nombres y Apellidos: " . $this->name;
      echo "<br/> Documento de Identidad: " . $this->document;
      echo "<br/> Correo: " . $this->email;
  }
}
?>

CODIGO en User.php

<?php

include_once('Account.php');

class User extends Account{
    public $foto;
    public $telefono;

    public function __construct($name, $document, $email, $foto, $telefono){
        parent:: __construct($name, $document, $email);
        $this->foto = $foto;
        $this->telefono = $telefono;
    }
}

?>

CODIGO en Driver.php

<?php

include_once('Account.php');

class Driver extends Account{
    public $foto;
    public $telefono;

    public function __construct($name, $document, $email, $foto, $telefono){
        parent::__construct($name, $document, $email);
        $this->foto = $foto;
        $this->telefono = $telefono;
    }

    public function showDataDriver(){
      echo "<h3>Informacion de Conductor:</h3>";
      echo "<br/> Nombres y Apellidos: " . $this->name;
      echo "<br/> Documento de Identidad: " . $this->document;
      echo "<br/> Correo: " . $this->email;
    }
}
?>

CODIGO en indexUser.php

<?php

require_once('Account.php');
require_once('User.php');
require_once('Driver.php');

$user1 = new User("Roberto Melchor", "84324823", "[email protected]", "foto1", "948598555");
$user1->showDataUser();

$user2 = new User("Segunda Torres", "82455553", "[email protected]", "foto2", "985984545");
$user2->showDataUser();

$conductor1 = new Driver("Carlos Dominguez", "85384383", "[email protected]", "fotoc1", "983459385");
$conductor1->showDataDriver();

$conductor2 = new Driver("Christian Oso", "64583758", "[email protected]", "fotoc2", "989379475");
$conductor2->showDataDriver();

?>

AL IMPRIMIR

Informacion de Usuario:

Nombres y Apellidos: Roberto Melchor
Documento de Identidad: 84324823
Correo: [email protected]

Informacion de Usuario:

Nombres y Apellidos: Segunda Torres
Documento de Identidad: 82455553
Correo: [email protected]

Informacion de Conductor:

Nombres y Apellidos: Carlos Dominguez
Documento de Identidad: 85384383
Correo: [email protected]

Informacion de Conductor:

Nombres y Apellidos: Christian Rodriguez
Documento de Identidad: 64583758
Correo: [email protected]

Implementando en PHP:

clase Account:

Clase User:

Clase Card:

Clase Index:


Manejando objetos con herencia (User,Card,Index):

JavaScript

User.js

class User extends Account
{
    constructor(id, name, document, email, password)
    {
        super(name, document)
        this.id = id;
        this.email = email;
        this.password = password;
    }

    printUserData()
    {
        console.log(this.name)
        console.log(this.id)
        console.log(this.email)
    }
}

Driver.js

class Driver extends Account
{
    constructor(id, name, document, email, password)
    {
        super(name, document)
        this.id = id;
        this.email = email;
        this.password = password;
    }

    printDriverData()
    {
        console.log(this.id)
        console.log(this.email)
    }
}

index.js

var driver1 = new Driver(10001,"Andrés Herrera", "AND123","[email protected]","passwordand01");

var uberX = new UberX("CVB123", driver1, "Chevrolet", "Spark");
uberX.passengers = 4;
console.log(uberX.brand);
console.log(uberX.model);
uberX.printDataCar();
driver1.printDriverData();

var user1 = new User(20001,"Andrea Ferra", "ANDA876","[email protected]","passworandy20");
user1.printUserData();

Solución de herencia en java

from account import Account


classUser(Account):
    def__init__(self, name, document):
        super().__init__(name, document)


from account import Account


classDriver(Account):
    def__init__(self, name, document):
        super().__init__(name, document)```

Clase Padre

public class Account {

    Integer id;
    String name;
    String document;
    String email;
    String password;

    public Account(Integer id, String name, String document, String email, String password) {
        this.id         = Math.random();
        this.name       = name;
        this.document   = document;
        this.password   = password;
        this.email      = email;
    }
}

Clases Hijas

class User extends Account{
public User(Integer id, String name, String document, String email, String password){
super(id, name, document, password, email);
}
}

class Driver extends Account{
String nroLicencia;

public Driver(Integer id, String name, String document, String email, String password, String nroLicencia){
    super(id, name, document, password, email);
    this.nroLicencia = nroLicencia;
}
}

Aclaracion: me parecio importante agregar a los datos del conductor su nro de licencia de CONDUCIR, tengo entendido que license de la clase car es algo totalmente distinto.

class Account {
  constructor(name, document) {
    this.id;
    this.name = name;
    this.document = document;
    this.email;
    this.password;
  }
}

class User extends Account {
  constructor(id, name, document, email, password) {
    super(id, name, document, email, password);
  }
}

class Driver extends Account {
  constructor(id, name, document, email, password) {
    super(id, name, document, email, password);
  }
}



JavaScript ❤️

Mi solución para Java, JavaScript y Python. Perdón por la mala resolución.

account:

class Account:
    id          = int 
    name        = str
    document    = str
    email       = str
    password    = str

    def __init__(self,id,name,document,email,password):
        self.id = id
        self.name = name
        self.document = document
        self.email = email
        self.password = password

driver:

from account import Account

class Driver(Account):
    def __init__(self,id,name,document,email,password):
        super().__init__(id,name,document,email,password)

user:

from account import Account

class User(Account):
    def __init__(self,id,name,document,email,password):
        super().__init__(id,name,document,email,password)

main:

from account import Account
from car import Car
from UberX import UberX
from driver import Driver
from user import User

if __name__ == "__main__":
    print("Hola mundo")

    '''car = Car("AMS234", Account("Andres Herrera", "ANDA876"))
    print(vars(car))
    print(vars(car.driver))

    uberX = UberX("AMS234", Account("Andres Herrera", "ANDA876"),"nissan","sentra");
    print(vars(uberX))
    '''
    user1 = User(1,"Chris","AND123","[email protected]","12345678")
    driver1 = Driver(1,"Andres Herrera","WOW123","[email protected]","87654321")
    
    print(vars(user1))
    print(vars(driver1))

Salida:

Ésta es mi solución en Java:

public class Account
{
    Integer id;
    String nombre;
    String document;
    String email;
    String password;

    public Account(String nombre, String document)
    {
        this.nombre = nombre;
        this.document = document;
    }
}

public class User extends Account {
    float credito;
    
    public User(String nombre, String document, float credito)
    {
        super(nombre, document);
        this.credito = credito;
    }   
}

public class Driver extends Account{
    float calificacion;
    String tipo_auto;
    
    public Driver(String nombre, String document, float calificacion, String tipo_auto)
    {
        super(nombre, document);
        this.calificacion = calificacion;
        this.tipo_auto = tipo_auto;
    }  
}

PHP
Clase Account

<?php 

class Account{
    public $id;
    public $name;
    public $document;
    public $email;
    public $password;

    public function __construct($name, $document){
        $this->name = $name;
        $this->document = $document;
    }

    public function printDataAccount(){
        echo "Nombre: ". $this->name."</br>";
        echo "Número Id: ".$this->document."</br>";
        echo "Email: ".$this->email."</br>";

    }
}



?>

Clase Driver

<?php 

require_once('account.php');

class Driver extends Account{
    
    public function __construct($name, $document, $email, $password){

        parent::__construct($name, $document);
        $this->email = $email;
        $this->password = $password;
    }
}


?>

Clase User

<?php 

require_once('account.php');

class User extends Account{

    public function __construct($name, $document, $email, $password){
        parent::__construct($name, $document);
        $this->email = $email;
        $this->password = $password;
    }
}

?>

package CursoPOOUber.Java;

class Account {

Integer id;
String name;
String document;
String email;
String password;

public Account (String name,String document){
    this.name = name;
    this.document = document; 

}

void printDataAccount(){
    System.out.println("License: " + name + " Name Driver: " + document);
}

}

package CursoPOOUber.Java;

public class Driver extends Account{

public Driver(String name,String document){
    super(name,document);
}

}

package CursoPOOUber.Java;

public class User extends Account{

String nameUser;

public User(String name,String document,String nameUser){
    super(name,document);
    this.nameUser=nameUser;
}

}

**Javascript **



Python



Php



Java



Reto completado!!!

Mi aporte en Java

Java (Clase User)
![](

Comparto mi codigo en Python:

JAVASCRIPT

class Account{

    constructor(name, document, email, password){
        this.id;
        this.name = name;
        this.document = document;
        this.email = email;
        this.password = password;
    }

    printDataCar(){
        console.log(this.name);
        console.log(this.document);
        console.log(this.email);
    }
}```



class User extends Account{
constructor(name, document, email, password){
super(name, document, email, password);
}
}

class Driver extends Account{
    constructor(name, document, email, password){
        super(name, document, email, password);
    }
}```
var car = new Car("ABC123", new Account("Diego Celis", "987987"))
car.printDataCar();

var uberX = new UberX ("MNB654", new Account("Laura", "654321"), "Renault", "Twingo");
uberX.printDataCar();

var user = new User ("Lupe", "1245", "[email protected]", "123");
user.printDataCar();```

Reto

from car import Car
from driver import Driver
from uber_x import uber_x

def run():

    print('Hola Mundo')

    car = Car("AMS234", Driver("Andres Herrera", "ANDA876", "[email protected]", "12345"))
    print(vars(car.driver))

    uberx = uber_x("FGH456", "Julia Estela", "Toyora", "Corolla")
    uberx.passenger = 4
    print(vars(uberx))


if __name__ == '__main__':
    run()
from account import Account

class User(Account):
    def __init__(self,id,name,document,email,password):
        super.__init__(id,name,document,email,password)
from account import Account

class Driver(Account):
    def __init__(self,id,name,document,email,password):
        super.__init__(id,name,document,email,password)

Java:
Main.java

class Main {

public static void main(String[] args) {
    System.out.println("Hola Mundo...");
    Car car = new Car("AMQ123", new Account("Andres Herrera", "AN123", "[email protected]", "12345"));
    car.passegenger = 4;
    car.printDataCar();

    System.out.println("UberX...");
    UberX uberX = new UberX("QWE567", new Account("Aandrea Herrera", "ANA567", "[email protected]", "654321"),"chevrolet", "sonic");
    uberX.passegenger = 3;
    uberX.printDataCar();
}

}

User.java:

class User extends Account{
public User(String name, String document, String email, String password){
super(name, document, email, password);
}

}

Driver.java:

class Driver extends Account {
public Driver(String name, String document, String email, String password){
super(name, document, email, password);
}
}

Python


from account import Account

class User(Account):

    def __init__(self, name, document):
        super().__init__(name, document)
from account import Account

class Driver(Account):

    def __init__(self, name, document):
        super().__init__(name, document)

python :

Reto 4
En Java

Python:

from account import Account

class user(Account):
    def __init__(self, name, document, email, password):
        super().__init__(name, document)
        self.email = email
        self.password = password

    def getName(self):
        return self.name

    def getDocument(self):
        return self.document

    def getEmail(self):
        return self.email

    def getPassword(self):
        return self.password

    def setName(self, name):
        self.name = name

    def setDocument(self, document):
        self.document = document

    def setEmail(self, email):
        self.email = email

    def setPassword(self, password):
        self.password = password

    def __str__(self):
        return 'Name: {}\nDocument: {}\nEmail: {}\nPassword: {}'.format(self.name, self.document, self.email, self.password)
from account import Account

class Driver(Account):
    def __init__(self, name, document, email, password):
        super().__init__(name, document)
        self.email = email
        self.password = password

    def getName(self):
        return self.name

    def getDocument(self):
        return self.document

    def getEmail(self):
        return self.email

    def getPassword(self):
        return self.password

    def setName(self, name):
        self.name = name

    def setDocument(self, document):
        self.document = document

    def setEmail(self, email):
        self.email = email

    def setPassword(self, password):
        self.password = password

    def __str__(self):
        return 'Name: {}\nDocument: {}\nEmail: {}\nPassword: {}'.format(self.name, self.document, self.email, self.password)

Python

class Account:
    id          = int
    name        = str
    document    = str
    email       = str
    password    = str

    def __init__(self, name, document):
        self.name       = name
        self.document   = document
from account import Account
 
class User(Account):

    def __init__(self, name, document, email, password):
        super().__init__(name, document, email, password)
from account import Account
 
class Driver(Account):

    def __init__(self, name, document, email, password):
        super().__init__(name, document, email, password)

JAVA

Super clase Account

package Java;

class Account {
    Integer id;
    String name;
    String document;
    String email;
    String password;
    
    //metodo constructor
    public Account(String name, String document){
        this.name=name;
        this.document=document;

    }
}

clases hijas :
Driver

package Java;

class Driver extends Account{

    public Driver(String name, String document){
        super(name, document);
    }
}

User

package Java;

class User extends Account{

    public User(String name, String document){
        super(name, document);
    }
}

JS
Account

class Account {
    constructor(name, document, email, password) {
        this.id;
        this.name = name;
        this.document = document;
        this.email = email;
        this.password = password;
    }
}

User

class User extends Account{

    constructor(name,document,email,password){
        super(name,document,email,password)
    }
}

Driver

class Driver extends Account{

    constructor(name,document,email,password){
        super(name,document,email,password)
    }
}

Python:

from account import Account

class User(Account) :
    def __init__(self, id, name, document, email, password) :
        super().__init__(id, name, document, email, password)
from account import Account

class Driver(Account) :
    def __init__(self, id, name, document, email, password) :
        super().__init__(id, name, document, email, password)

Python


Buenas tardes compañeros, les anexo mi aporte




var user = new User('Mateo Florez', '102547747', '1');
var car = new UberX('GRD-547', user, 'Chevrot', 'Spark');
car.printDataUberX();
user.printDataUser();
class User extends Account {

    constructor(name, document, idUser) {
        super(name, document);
        this.idUser = idUser
    }


    printDataUser () {
        console.log(this.idUser);
        console.log(this.name);
    }
}
class Driver extends Account {

    constructor(name, document, idDriver) {
        super(name, document);
        this.idDriver = idDriver
    }
}

Clase Account en Java:

public class Account {
    Integer id;
    String name;
    String document;
    String email;
    String password;
    
    public Account(String name, String document, String email, String password){
        this.name = name;
        this.document = document;
        this.email = email;
        this.password = password;
    }

    void printUsrData(){
        System.out.println(name + "    " + document + "   " + email + "   " + password);
    }
}

Clase Driver:

class Driver extends Account{
    public Driver(String name, String document, String email, String password){
        super(name, document, email, password);
    }
}

Clase User:

class User extends Account{
    public User(String name, String document, String email, String password){
        super(name, document, email, password);
    }
}

Archivo Main:

class Main {
    public static void main(String[] args) {

        System.out.println("\nHola mundo!\n");
        Car car = new Car("AMQ123", new Account("Andres Herrera", "AND123", "[email protected]","pass***"));
        car.passenger = 4;
        car.printDataCar();
        
        Driver driver = new Driver("Jorge", "JOR343", "[email protected]", "pass***");
        driver.printUsrData();

        Car car2 = new Car("QWE567", new Account("Andrea Herrera", "ANDA876", "[email protected]", "pass****"));
        car2.passenger = 3;
        car2.printDataCar();

        User usr = new User("Jaime", "JAI506", "[email protected]", "pass**** \n");
        usr.printUsrData();
    }
}

Javascript:

Así me quedó la familia Account:

Clase User:

public class User extends Account {

    

    public User (int id,String name, String document, String email, String password){

        super(id,name,document,email,password);
        this.id = id;

    }

    void printDataUser(){

        System.out.println("Passenger: " + name + " id: " + id);

    }


    }

Clase Driver:

public class Driver extends Account{

    public Driver (int id, String name, String document, String email, String password){

        super(id, name, document, email, password);

    }

    void printDataDriver(){

        System.out.println("Conductor: " + name + " id: " + id);

    }
    
}

Main:

class Main {

    public static void main(String[] args) {
        System.out.println("Hola mundo");

        Car car = new Car("AMQ123", new Account(572, "Alan Ayala", "CAAO12","[email protected]","123123"));
        car.id = 65;
        car.passegenger = 4;

        car.printDataCar();

        Car car2 = new Car("QWE657", new Account(698, "Andrea Herrera", "AND123", "[email protected]", "qwerty123"));
        car2.passegenger = 3;

        car2.printDataCar();

        Payments payment = new Payments(123);

        payment.printDataPayment();

        Payments card = new Card(456, 789456, 489, "30/03/2023");
        card.printDataPayment();

        Payments payPal = new Paypal(473, "[email protected]"); 
        payPal.printDataPayment();

        Account cuenta = new Account(7619, "Lupita", "MEC734", "[email protected]", "73491827");
        cuenta.printDataAccount();

        Driver driver = new Driver(497, "Rodrigo", "QSY76", "[email protected]", "763198Apo");
        driver.printDataDriver();

        User user = new User(493, "Emilio", "QOP123", "[email protected]", "SUUUUUI");
        user.printDataUser();



    }

}

Aquí les dejo mi versión.

Hola. Yo plasmé la herencia en lenguaje JavaScript:

class User extends Account {

public User (String name, String document, String email, String password){
    super (name,document,email,password);

}

}

PHP

JavaScript


Account.js

class Account{
    constructor(name,document,email,password)
    {
        this.name =name;
        this.document = document;
        this.email = email;
        this.password = password;
    }
        
}

User.js

class User extends Account
{
    constructor(name,document,email,password)
    {
       super(name,document,email,password)
    }
        
    print_info=()=>
    {
        console.log("User\n")
        console.log("Name: ",this.name)
        console.log("ID: ",this.document)
        console.log("Email: ",this.email)
        console.log("Password: ",this.password)

    }
}

Driver.js

class Driver extends Account
{
    constructor(name,document,email,password)
    {
       super(name,document,email,password)
    }
        
    print_info=()=>
    {
        console.log("Driver\n")
        console.log("Name: ",this.name)
        console.log("ID: ",this.document)
        console.log("Email: ",this.email)
        console.log("Password: ",this.password)

    }
}

index.js

// get new instance
var user = new User("Alejandro","25x645","[email protected]","******")
var driver = new Driver("Robinson","356-87-882","[email protected]","****")
var uber_pool = new UberPool("AW456",driver,"BMW","2022");

// call methods
user.print_info()
driver.print_info()
uber_pool.print_info()

index.html

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>
<body>
    <h1>Programación Orientada a Objetos en JavaScript</h1>
</body>
<script src="Account.js"></script>
<script src="User.js"></script>
<script src="Driver.js"></script>
<script src="Car.js"></script>
<script src="UberPool.js"></script>
<script src="index.js"></script>
</html>

Resultados por consola

User
					
Name:  Alejandro 					User.js:11:17
ID:  25x645 						  User.js:12:17
Email:  [email protected] 		User.js:13:17
Password:  ******			User.js:14:17
Driver
					
Name:  Robinson 		Driver.js:11:17
ID:  356-87-882 		Driver.js:12:17
Email:  [email protected] 	Driver.js:13:17
Password:  ****	 	Driver.js:14:17
License:  AW456 		UberPool.js:10:17
Brand:  BMW 			UberPool.js:11:17
Model:  2022 			UberPool.js:12:17

Javascript

class User extends Account {
    constructor (id, name, document, email, password) {
        super(id, name, document, email, password,);
}}

Python

from account import Account
class Driver(Account):
    def __init__(self, id, name, document, email, password):
        super.__init__(id, name, document, email, password)

PHP

<?php
    require_once('Account.php');
    class User extends Account {

        public function __construct($id, $name, $email, $password) {
            parent:: __construct($id, $name, $email, $password);
        }
    }
?>

Java

public class User extends Account {
    
    public User (Integer id, String name, String document, String email, String password) {
        super(id, name, document,email, password);
    }
}

Acá es donde me doy cuenta que Amo javaScript xd

clase account modificada por si acaso siga viniendo sin email ni password

class Account {
        name;
        document;
        email;
        password;

    constructor(name, document, email =null, password = null) {
        this.id;
        this.name = name;
        this.document = document;
        if (email != null) { this.email=email; }
        if (password != null) { this.password=password; }
    }

    printDataAccount(){
         console.log(`name: ${this.name} , document: ${this.document}
         , email: ${this.email} , password: ${this.password}` )
    }
}

Por otro lado la clase User :

class User extends Account{

    constructor(name,document, email , password){
        super(name , document , email , password)
    }

    printDataUser(){
        this.printDataAccount();
    }
}

Ejemplo en Python

account.js

class account{
    constructor(name,document){
        this.id = id;
        this.name = name;
        this.document = document;
        this.email = email;
        this.password =password; 
    }
}

class user extends account(){
    constructor(id,name,document,email,password){
        super(id);
        super(name);
        super(document);
        super(email);
        super(password);
    }
}

class driver extends account(){
    constructor(id,name,document,email,password){
        super(id);
        super(name);
        super(document);
        super(email);
        super(password);
    }
}

payment.js

class payment{
constructor(id){
    this.id = id;
    }
}

class paypal extends payment(){
    constructor(id,email){
        super(id)
        this.email = email;
    }
}
class card extends payment(){
    constructor(id,cvv,franchise,expiration_date){
        super(id);
        this.cvv = cvv;
        this.franchise = franchise;
        this.expiration_date = expiration_date;;
    }
}

class cash extends payment(){
    constructor(id){
        super(id);
    }
}

route.js

class Route{
    constructor(){
    this.id;
    this.init;
    this.end;
    }
} 

uber.js

class uber{
    constructor(license,document,driver,passangers,brand){
        this.id = id;
        this.license =license;
        this.document = document;
        this.driver = driver;
        this.passangers = passangers;
        this.brand = brand;
    }
    prinDateUber(){
        console.log(this.driver);
        console.log(this.driver.name);
        console.log(this.driver.document);
    }
}

class uber_x extends uber{
    constructor(id,license,document,driver,passangers,brand,model){
        super(id,license,document,driver,passangers,brand);
        this.model = model;
    }
}

class uber_pool extends uber{
    constructor(id,license,document,driver,passangers,brand,model){
        super(id,license,document,driver,passangers,brand);
        this.model = model;
    }
}

class uber_black extends uber{
    constructor(id,license,document,driver,passangers,brand,type_card_acepted,seats_material_acepted){
        super(id,license,document,driver,passangers,brand);
        this.type_card_acepted = type_card_acepted;
        this.seats_material_acepted = seats_material_acepted;
    }
}

class uber_van extends uber{
    constructor(id,license,document,driver,passangers,brand,type_card_acepted,seats_material_acepted){
        super(id,license,document,driver,passangers,brand);
        this.type_card_acepted = type_card_acepted;
        this.seats_material_acepted = seats_material_acepted;
    }
}


El reto
Estos son los modulos:
modulo account

class Account:
    id = int
    name = str
    document = str
    email = str
    password = str

    def __init__(self, name, document):
        self.name = name
        self.document = document

modulo driver

from account import Account

class Driver(Account):


    def __init__(self, name, document):
        super().__init__(name, document)
        

    def PrintDataDriver(self):
        print("Document :".format({}),self.document)
        print("Full driver name: ".format({}),self.name)

modulo user

from account import Account

class User(Account):


    def __init__(self, id, name, document, email, password):
        super().__init__(name, document)
        self.id = id
        self.email = email
        self.password = password


    def PrintDataUser(self):
        print("Id :".format({}),self.id)
        print("Full user name:".format({}),self.name)
        print("Email :".format({}),self.email)
        print("Password :".format({}),self.password)

modulo car

from driver import Driver

class Car:
    id = int
    license = str
    driver = Driver("","")
    passenger = int

    def __init__(self, license, driver):
        self.license = license
        self.driver = driver

    
    def PrintDataCar(self):
        print("License :".format({}),self.license)

modulo uberX

from car import Car

class UberX(Car):
    brand = str
    model = str

    def __init__(self, license, driver, brand, model):
        super().__init__(license,driver)
        self.brand = brand
        self.model = model

    
    def PrintDataCar(self):
        print("License :".format({}),self.license)
        print("Brand:".format({}),self.brand)
        print("Model :".format({}),self.model)

modulo main

from car import Car
from uberX import UberX
from driver import Driver
from user import User

if __name__ == "__main__":
    
    car = Car("AMS234", Driver("Andres Herrera", "ANDA876"))
    car.PrintDataCar()
    car.driver.PrintDataDriver()

    print("*" * 50)
    car2 = Car("QWE567", Driver("Marta", "MSAE567"))
    car2.PrintDataCar()
    car2.driver.PrintDataDriver()

    print("*" * 50)
    uberX = UberX("FGHT678", Driver("Raul Perez","RFGT567"),"Chevrolet","Spark")
    uberX.PrintDataCar()
    uberX.driver.PrintDataDriver()

    print("*" * 50)
    user1 = User("UH8900045","Miguel Angel Rodriguez","MALM8978","[email protected]","df5&4g/#4")
    user1.PrintDataUser()

Y esta es la salida en la terminal
![](

En python, de acuerdo a lo que he entendido, cualquier corrección la agradezco.

Reto: Jerarquia de Account en Java

User

Driver

Para este reto, no considere las subclases propuestas, cree el parámetro “Tipo de cuenta” para indicar si es usuario o conductor. Mientras se tengan esos datos comunes se puede hacer, cuando se tengan más datos diferentes si se podría hacer las subclases.

JavaScript

![](

PHP
![](

PYTHON

![](

JAVA

(ESTOY APREDIENDO A MANEJAR Y ME LANZA UNOS ERRORES PERO ES TEMA DE SINTAXIS)

Lo dejo en Python que es el lenguaje en el que me estoy entrenando:
Class Account:

class Account:
    id          = int
    name        = str
    document    = str
    email       = str
    password    = str

    def __init__(self, name, document):
        self.name = name
        self.document = document

Class User:

from account2 import Account

class User(Account):

    def __init__(self, name, document):
        super().__init__(name, document)

Class Driver:

from account2 import Account

class Driver(Account):

    def __init__(self, name, document):
        super().__init__(name, document)

Les comparto mi código de JavaScript. 😄
Link del repositorio en GitHub.

index.js

account.js

user.js

driver.js

Lo hice en Python, le agregué algunas cosas más:

Un supuesto archivo de accounts.csv con todos los id que se encuentran dentro de Uber (esto normalmente iría en una clase o función Main, pero por el ejercicio lo incluí de una en la clase Account). Este archivo se usa para la función Login, donde se hace una validación si el id se encuentra dentro de esta lista de ids.

También le agregué a cada clase hija un atributo adicional relacionado a temas de dinero.

import numpy

accountsid_file = open("accounts.csv")
accountsid_array = np.loadtxt(accounts_file, delimiter=",")  

class Account:
		id = int
		name = str
		document = int
		email = str
		password = str

		def __init__(self, id, name, document, email, password):
				self.id = id
				self.name = name
				self.document = document				
				self.email = email
				self.passwrod = password

		def login(self, id):
				if id in accountsid_array:  
						log_status = True
				else: log_status = False 
				return log_status

class User(Account):
		wallet_balance = int
		
		def __init__(self, id, name, document, email, password):
				super().__init__(id, name, document, email, password)
		
		def login(self, id):
				super().login(id)		

class Driver(Account):
		earnings = int
		
		def __init__(self, id, name, document, email, password):
				super().__init__(id, name, document, email, password)

		def login(self, id):
				super().login(id)

En lenguaje Java.
Account

public class Account {
    Integer id;
    String name;
    String document;
    String email;
    String password;

 public Account(Integer id,String name, String document, String email, String password){
    this.id = id;
    this.name = name;
    this.document = document;
    this.email = email;
    this.password = password;
   } 
}

User

class User extends Account{
    public User(Integer id,String name,String document,String email,String password){
        super(id, name, document, email, password);
    }
    void printDataUser(){
        System.out.println("User id: "+id+"\nName: "+name+"\nDocument: "+document+"\nEmail: "+email);
    }
}

Driver

class Driver extends Account{
    public Driver(Integer id,String name,String document,String email,String password){
        super(id, name, document, email, password);
    }
    void printDataDriver(){
        System.out.println("User id: "+id+"\nName: "+name+"\nDocument: "+document+"\nEmail: "+email);
    }
}

Muestro como quedaría con User en JavaScript:

class User extends Account {
    constructor(name, document, email, password) {
        super(name, document);
        this.email = email;
        this.password = password;
    }

    showDetails() {
        console.log(`User details:
        ${this.name}
        ${this.document}
        ${this.email}`);
    }
}

const user = new User("Juan", 1234, "[email protected]", "supersegura123");
user.showDetails();

SOLUCION AL RETO EN JAVA
Incluyo en el dataCar marca y modelo.

 class Main 
{
  public static void main(String[] args) 
  {
    System.out.println("Inicializando....");
    System.out.println("Espere un segundo / Wait a moment please!! ...\n");
        
    UberX uberX = new UberX("QME122", "4", "BMW", "Sportive", new Driver("Juan Martinez", "JUAN123", "[email protected]", " password oculto"));
    uberX.printDataCar();
    System.out.println("\nData Driver");
    uberX.driver.printDataAccount();
    System.out.println("\nData User");
    User u = new User("Fernando", "LL22", "[email protected]", " Password oculto \n\n");
    u.printDataAccount();
      


  }

}

Account Abajo



public class Account 
{
   Integer id;
   String name;
   String document;
   String email;
   String password;
   
   public Account(String name, String document, String email, String password) 
   {
      this.name = name;
      this.document = document;
      this.email = email;
      this.password = password;
   }

   void printDataAccount()
   {
      System.out.println("\n\t Document: " + document + "\n\t Name: " + name + "\n\t Email: " + email + "\n\t Password: " + password);

   }


}



++ CAR ++ abajo



class Car
{
    Integer id;
    String license;
    Account driver;
    String passenger;
    String brand;
    String model;

    public Car(String license, Account driver, String passenger, String brand, String model) 
    {
        this.license = license;
        this.driver = driver;
        this.passenger = passenger;
        this.brand = brand;
        this.model = model;
    }

    void printDataCar()
    {
        System.out.println("\nData Car \n" + "\n\tCar license : " + license + "\n\tPassengers  : " + passenger + "\n\tMarca coche : " + brand  + "\n\tModelo      : " + model);

    }

}

uBerX


class UberX extends Car 
{
    

     public UberX(String license, String passenger, String brand, String model, Account driver)
     {
         super(license, driver, passenger, brand, model);
        
     }

}

RESULTADO

Inicializando....
Espere un segundo / Wait a moment please!! ...


Data Car

        Car license : QME122
        Passengers  : 4
        Marca coche : BMW
        Modelo      : Sportive

Data Driver

         Document: JUAN123
         Name: Juan Martinez
         Email: [email protected]
         Password:  password oculto

Data User

         Document: LL22
         Name: Fernando
         Email: [email protected]
         Password:  Password oculto


******pd: os saldrá error en uberVan , uberPool etc solo teneis que colocar como en uberX el brand y model.

Espero que os sirva de ayuda estuve 4 horas atascado buceando entre soluciones******

class Account {
Integer id;
String name;
String document;
String email;
String password;

public Account(String name, String document){
    this.name = name;
    this.document = document;
}

void printName()
{
    System.out.println(name);
}

}

class User extends Account {
public User(String name, String document){
super(name, document);
}
}

class Driver extends Account{
String driversLicense;

public Driver(String name, String document, String driversLicense){
    super(name, document);
    this.driversLicense = driversLicense;
}

}

class Main {
public static void main(String[] args) {
Driver driver = new Driver(“Joaquin”, “12345CBA”, “P”);
driver.printName();
System.out.println(driver.driversLicense);
}
}

User.java


class User extends Account{
    String name;
    String document;

    public User(String name, String document){
        super(id,name, email, password);
        this.name =name;
        this.document=document;
        
    
    }

}

Driver.java


class Driver extends Account{
    String name;
    String document;

    public Driver(String name, String document){
        super(id,name, email, password);
        this.name =name;
        this.document=document;
        
    
    }

}

Python:


Mi aporte en lenguaje Java