<?php class father{ //定义father类 //定义private修饰的类成员和方法 private $hair='curly hair'; private function smoke(){ echo '我有吸烟的习惯.'; } } class son extends father{ //定义继承自father类的son类 //定义访问private修饰的类成员的方法 public function get_property(){ $this->hair; $this-&
class A { public: typedef int* pointer; }; class B :public A { public: pointer b; }; 这段代码运行没有问题,子类继承了父类定义的类型pointer. 但当普通类变成模板类时: template<class T> class A { public: typedef T* pointer; }; template<class T> class B :public A<T> { public:
子类(父类的外部包)中访问父类的protetcted属性或者方法,是不可以通过创建父类对象调用的.注意:此处不讨论同包下的父类子类,因为同包下所有类都可访问protected属性或者方法. 请参见Java官方文档:Chapter 6. Names中的6.6.2.1. Access to a protected Member具体例子如下: 父类C:在包c下 1 package c; 2 public class C { 3 protected int id; 4 protected void te
#include <iostream> using namespace std; class Father { public: virtual void show() { cout<<"this is Father"<<endl; } }; class Son:public Father { public: virtual void show() { cout<<"this is Son"<<endl; }