class Person {
public name: string;
}
class Animal {
public name: string;
}
let p: Person;
let a: Animal;
p = a;
a = p;
- 只能将
多 的属性赋值给 少 的,不可将 少 的属性赋值给 多 的
class Person {
public name: string;
public age: number;
}
class Animal {
public name: string;
}
let p: Person;
let a: Animal;
// 多????少
a = p;
// 少????多
p = a;
class Person {
public name: string;
public static age: number;
constructor(name: string, age: number) {
}
}
class Animal {
public name: string;
constructor(name: string, age: number) {
}
}
let p: Person;
let a: Animal;
a = p;
p = a;
私有属性:
class Person {
private name: string;
}
class Animal {
private name: string;
}
let p: Person;
let a: Animal;
p = a;
a = p;
受保护属性:
class Person {
protected name: string;
}
class Animal {
protected name: string;
}
let p: Person;
let a: Animal;
p = a;
a = p;
|
请发表评论