ProgrammingModerateTCS NQT Prime · Infosys SP
What is printed?
What is printed?
int x = Integer.MAX_VALUE; long y = x + 1; long z = x + 1L; System.out.print(y + " " + z);
- A. -2147483648 2147483648
- B. 2147483648 2147483648
- C. -2147483648 -2147483648
- D. 2147483648 -2147483648
Correct answer: A. -2147483648 2147483648
x + 1 is evaluated in int and overflows before widening; x + 1L is evaluated in long.
More OOP with C++ and Java questions
- What is printed? java class A { A() { this(1); System.out.print("0"); } A(int x) { System.out.print("1"); } } class B extends A { B() {…
- Which OOP principle bundles data with the methods that act on it and hides the internal state behind an interface?
- In Java, which keyword makes one class inherit from another class?
- What is the return type of a C++ constructor?
- Every Java class that declares no superclass implicitly extends:
- In C++, members of a class declared without any access specifier are: