← Back to Inheritance
Question 448
Interface With Two Pure Virtual Methods
Interface With Two Pure Virtual Methods
An interface is an abstract class made only of pure virtual methods. A concrete subclass must implement EVERY one of them. Create an abstract classDevicewith TWO pure virtual methods: -string name() const(returns the device name) -int power() const(returns watts) Then create a concrete classLaptopthat implementsname()returning "Laptop" andpower()returning 65.Devicecannot be instantiated; the runner uses aDevice*to aLaptopand prints the output shown in Expected Output. Do NOT write a main function.
Expected Output:
Laptop 65= newline. The output ends with a newline — print one after the last line.
Hints4 available
Sign in to use hintsTopics:
Inheritance
1
Tab to indent (Esc then Tab to move on) · Ctrl+Enter to run · Shift+Alt+F to format · Ctrl+Space to expand shortcuts (cout, fori)
Your Output
Run your code to see the output here...
Test Cases
Run your code to see test case results.