Python 101

Here's a Python class followed by its Java equivalent.

Python:

class Employee:
  def __init__(self, fname="John", lname="Doe", id=1, manager=None, dept=1):
        self.__firstName     =     fname
        self.__lastName      =     lname
        self.__id            =     id
        self.__manager       =     manager
        self.__dept          =     dept

  def getManager(self):
        return self.__manager

  def __str__(self):
        values = self.__lastName, self.__firstName, self.__id
        return join(values,',')

Java:

 public class Employee{ private String firstName, lastName; private int id, dept; private Employee manager; public Employee(){ firstName = "John"; lastName = "Doe"; id = 1; vmanager=null; dept=1; } public Employee(String fname, String lname, int id, Employee manager, int dept){ firstName = fname; lastName = lname; this.id = id; ...

Get Python Programming with the Java™ Class Libraries: A Tutorial for Building Web and Enterprise Applications with Jython now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.