有如下类和对象的定义: c1ass Constants{ public; static double getPIO {retum 3.1416;) }; Constants constants, 下列各组语句

admin2020-04-07  44

问题 有如下类和对象的定义:
    c1ass Constants{
    public;
    static double getPIO {retum 3.1416;)
    };
    Constants constants,
    下列各组语句中,能输出3.1416的是(    )。

选项 A、cout<<constants—>getPI();和cout<<Constants::gerPI();
B、cout<<constants.getPI();和cout<<Constants.getPI();
C、cout<<constants—>getPI();和cout<<Constants—>getPI();
D、cout<<constants.getPI();和cout<<Constants::getPI();

答案D

解析 此题考查的是静态成员函数的引用。getPI()是类Constan ts的静态成员函数。引用静态成员函数可以有两种形式:一是通过类名直接进行调用,例如类名::静态成员函数名:另一种是用类的任何对象名进行调用其作用仅是通过对象名间接的指出类名,例如constants.getPI()选项D即是这种调用方式。
转载请注明原文地址:https://jikaoti.com/ti/cLA0FFFM
0

最新回复(0)