014-007-006
Defining final Methods
Easy
Problem Description
Defining final Methods
In this problem, you will create a program that defines a non-overridable getSecretCode() method using the final modifier in the Security class, calls it from the subclass SecureApp, and displays the result to standard output.
Learning Objective: Understand how to prevent overriding using the final keyword
Overview
Create a program that defines a non-overridable method using the final modifier.
Input
Secret code (one line string)
Specifications
- Security class receives the secret code through its constructor and stores it in a field
- Define final method getSecretCode() in Security class (returns the stored secret code)
- SecureApp class extends Security
- Create showCode() method in SecureApp that outputs getSecretCode() result
- In Main, read the secret code from standard input, pass it to SecureApp for testing
Output Format
Code: secretCode
Example
Input:
SECRET123
Output:
Code: SECRET123
Ready to Try Running Code?
Log in to access the code editor and execute your solutions for this problem.
Don't have an account?
Sign Up