最近在加强JAVA和Python,今天刚看了Python中类的定义,与其他的都不同,做一下笔记
PHP:
class A entends B {
public $a;
public function __construct($a){
$this->a=$a;
}
}
调用时$a = new A(x)
JAVA:
class A entends B {
private int a;
A(int x){
this.a = x;
}
调用时A a = new A(2);
Python:
class Student(object):
def __init__(self,name,age):
self.__name = name
self.__age = age
def outp(self):
print(self.__name)
print(self.__age)
Goodstudent(Student):
def __init__(self,name):
self.__name = name
self.__age = 99
调用时a = Goodstudent("tom")
a.outp()