Weapon w = new Weapon(42); is that correct?

Asked

Viewed 78 times

-1

Had this question in a programming test Consider the Abstract Weapon class. Does the code line below present an error? Justify your answer.

Weapon w = new Weapon(42);

That is my answer and the teacher considered nothing yes, can not have value within Weapon

the correct would be as it is down here /

Weapon w = new Weapon( );
  • 3

    The question is whether the line is correct? if Weapon is abstract nor has as instantiating soon... I go from NDA

1 answer

1


In fact the two modes are incorrect because an abstract class cannot be instantiated. An abstract class (in the Weapon case) is only a class model that other classes will inherit.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.