ProgrammingEasyHCL · Tech Mahindra pattern
A variable declared inside a Java interface is implicitly:
- A. public static final
- B. private static
- C. public and per-object
- D. protected final
Correct answer: A. public static final
Interface fields are constants: public, static and final whether you write those words or not, and they must be initialised where they are declared.
More OOP with C++ and Java questions
- What is printed? cpp class A { public: A() { cout << "A"; } ~A() { cout << "a"; } }; class B : public A { public: B() { cout << "B"; }…
- What is printed? java class C { static int n = 0; C() { n++; } } // in main: for (int i = 0; i < 3; i++) new C(); C c = new C()…
- In Java, final applied to a class, a method and a variable means, respectively:
- What is printed? java List<Integer> list = new ArrayList<>(); list.add(1); list.add(2); list.add(1, 5); System.out.print(list);
- What is printed? java Set<String> s = new HashSet<>(); s.add("a"); s.add("b"); s.add("a"); System.out.print(s.size() + " " + s.add("b"));
- What is printed? java try { System.out.print("T"); throw new RuntimeException(); } catch (Exception e) { System.out.print("C"); } finally…