📜  Java |运营商|问题8

📅  最后修改于: 2021-07-02 16:59:20             🧑  作者: Mango

class demo
{
    int a, b, c;
    demo(int a, int b, int c)
    {
        this.a = a;
        this.b = b;
    }
      
    demo()
    {
        a = b = c = 0;
    }
      
    demo operator+(const demo &obj)
    {
        demo object;
        object.a = this.a + obj.a;
        object.b = this.b + obj.b;
        object.c = this.c + obj.c;
        return object;
    }
}
  
class Test
{
    public static void main(String[] args)
    {
  
        demo obj1 = new demo(1, 2, 3);
        demo obj2 = new demo(1, 2, 3);
        demo obj3 = new demo();
  
        obj3 = obj1 + obj2;
        System.out.println ("obj3.a = " + obj3.a);
        System.out.println ("obj3.b = " + obj3.c);
        System.out.println ("obj3.c = " + obj3.c);
  
    }
}

(B)编译错误
(C)运行时错误
(D)分割错误答案: (B)
说明: Java不支持运算符重载。它仅支持方法重载,而C++同时支持方法和运算符重载。
这个问题的测验
如果您在以上帖子中发现任何错误,请在下面发表评论