ProgrammingModerateCognizant GenC · Accenture
Which statement about abstract classes in Java is correct?
- A. An abstract class can be instantiated with new if all its methods are implemented
- B. An abstract class cannot contain any concrete method
- C. An abstract class may declare constructors, which run when a subclass object is created
- D. A class containing an abstract method need not be declared abstract
Correct answer: C. An abstract class may declare constructors, which run when a subclass object is created
Abstract classes cannot be instantiated directly, but their constructors are invoked through the subclass constructor chain; they can mix abstract and concrete methods.
More OOP with C++ and Java questions
- In C++, a Base pointer holds a Derived object created with new, and the Base destructor is NOT virtual. What happens on delete basePtr?
- What is printed? java static void f(int x) { System.out.print("int"); } static void f(long x) { System.out.print("long"); } static void…
- What happens when this C++ program is compiled? cpp struct B { int x = 5; }; class D : B { }; int main() { D d; cout << d.x; }
- What is printed? java static int f() { try { return 1; } finally { System.out.print("F"); } } public static void main(String[] a) {…
- In Java, an interface declares int MAX = 10;. What happens if an implementing class executes MAX = 20; ?
- What is printed? (C++, assume <iostream> and using namespace std) cpp struct A { A() { cout << "c"; } A(const A&) { cout << "k"; } ~A() {…