Weapon w = new Weapon (42); Is that correct? [duplicate]

-1

Had this question in a programming test Consider the Abstract class Weapon. Does the line of code below display any errors? Justify your answer.

Weapon w = new Weapon(42);

This is my answer and the teacher did not consider anything yes, it can not have value inside Weapon

The correct one would be like down here /

Weapon w = new Weapon( );
    
asked by anonymous 01.12.2017 / 17:43

1 answer

1

Actually both modes are incorrect because an abstract class can not be instantiated. An abstract class (in the Weapon case) is only a class model that other classes will inherit.

    
01.12.2017 / 17:53