ProgrammingVery hardProduct-company placement · Java

Which lines fail to compile?

Which lines fail to compile?
class P { void f() { } static void g() { } }
class C extends P {
    static void f() { }   // L1
    void g() { }          // L2
}
  1. A. L1 only
  2. B. L1 and L2
  3. C. L2 only
  4. D. Neither: L1 hides f and L2 overrides g

Correct answer: B. L1 and L2

A static method cannot hide an instance method (L1) and an instance method cannot override a static one (L2); both are compile-time errors.

More OOP with C++ and Java questions

Exams that ask this topic