Java与python的面向对象对比

版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/i973635025/article/details/82684789

Java

Python

public class Employee {
    public static int empCount = 0;
    String name;
    int salary;
    public Employee(String name, int salary)
    {
        this.name = name;
        this.salary = salary;
    }
    public void displayCount()
    {
        System.out.print("Total Employee " + Employee.empCount);
    }
    public void displayEmployee()
    {
        System.out.print("Name : " + this.name +  ", Salary: " + this.salary);
    }
}

 

class Employee:

   '所有员工的基类'

   empCount = 0

 

   def __init__(self, name, salary):

      self.name = name

      self.salary = salary

      Employee.empCount += 1

  

   def displayCount(self):

     print "Total Employee %d" % Employee.empCount

 

   def displayEmployee(self):

      print "Name : ", self.name", Salary: ", self.salary

 

empCount静态变量

__init__构造器

selfthis

猜你喜欢

转载自blog.csdn.net/i973635025/article/details/82684789