面向对象的perl

1 类:
类名称:
package Person;

构造函数:
sub new {
		my $self = {}; 
		$self->{NAME}  = undef;
		$self->{AGE}   = undef;
		$self->{PEERS} = [];
		bless($self);    
	}




2 继承
 ######################################
package Man;
########################################
@ISA = ("Person");
 
sub new{
 	my $self = {};
 	bless ($self);
 }


3 调用:
  my $man = Man->new;
  $man->name('ssss'); 
  print $man->age(18);


注意一定要为子类对象定义显式的构造函数,否则创建的总是person对象,而非Man对象

你可能感兴趣的:(java,perl)