ProgrammingModerateWipro · Capgemini pattern
What is printed?
What is printed?
System.out.print("placement".substring(2, 5) + "placement".indexOf('e'));- A. ace6
- B. acem4
- C. lac4
- D. ace4
Correct answer: D. ace4
Indices: p0 l1 a2 c3 e4 m5 e6 n7 t8. substring(2, 5) takes indices 2 to 4 (end excluded): "ace". indexOf('e') gives the first e, at 4.
More OOP with C++ and Java questions
- What is the time complexity of get(i) on a Java ArrayList and on a LinkedList?
- In C++, what does new do that malloc does not?
- What is printed? java class A { void show() { System.out.print("A"); } } class B extends A { void show() { super.show()…
- What is printed? cpp class Base { public: void show() { cout << "B1"; } virtual void vshow() { cout << "B2"; } }; class Derived : public…
- In C++, Base has a non-virtual destructor and Derived : public Base owns a heap buffer freed in ~Derived. What happens on: Base p = new…
- What is printed? java String a = "hi"; String b = "hi"; String c = new String("hi"); System.out.print((a == b) + " " + (a == c) + " " +…