Java | Operators | Question 8
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); } } |
chevron_right
filter_none
(B) Compile Error
(C) Run Time Error
(D) Segmentation Fault
Answer: (B)
Explanation: Operator overloading is not support by JAVA. It only supports method overloading, whereas C++ supports both method and operator overloading.
Quiz of this Question
Please comment below if you find anything wrong in the above post
Recommended Posts:
- Java | Operators | Question 7
- Java | Operators | Question 4
- Java | Operators | Question 2
- Java | Operators | Question 5
- Java | Operators | Question 6
- Java | Operators | Question 9
- Java | Operators | Question 1
- Java | Operators | Question 3
- Operators in Java
- Bitwise operators in Java
- Bitwise right shift operators in Java
- Compound assignment operators in Java
- Operators in C | Set 2 (Relational and Logical Operators)
- C | Operators | Question 12
- C | Operators | Question 13




