定义 静态成员:又称类成员,使用static修饰符的方法和变量: 非静态成员:又称实例成员,未使用static修饰符的方法和变量. 结论 注:jdk1.8 测试源码 public class Main { private int x = 34; // 非静态变量 private static int a = 1; // 静态变量 private static int b = a; //[√] 静态变量调用静态变量 private static int c = getA(); //[√] 静态变量…
/* 样例1: class Parent{ int num = 3; } class Child extends Parent{ int num = 4; } */ /* 样例2: class Parent{ } class Child extends Parent{ int num = 4; } */ /* 样例3: class Parent{ void show(){ System.out.println("Parent Show!"); } } class Child exten…
举个例子: 定义了一个类的const实例,怎么让他也能调用非能调用非const成员函数class foo{public:void test1() {cout << "I am not a const member function" << endl;}void test2()const {foo *temp = (foo*)this;//注意这个转换!!!temp->test1();}}; int main() {foo f;f.test2();retur…