编写一个c++程序(一定要体现面向对象)

2025-02-27 05:56:57
推荐回答(1个)
回答1:

面向对象的特征
封装 继承 多态
abstract class Animal{ //封装性
public void cry(String str){
System.out.println(str);
}
}
class Dog extends Animal{} //继续
class Cat extends Animal{}
class Demo{
public static void main(String 字符串[])
{
Dog dog1 = new Dog();
Cat cat1 = new Cat();
dog1.cry("wangwang...."); ///多态的体现
cat1.cry("miaomiao.....");
}
}