User Input
Java
OOP
Public
Java
The Java programming language is a simple, modern, general-purpose, object-oriented programming language. Having a basic familiarity with the programming language used on the job is a prerequisite for quickly getting up to speed.
OOP
Object-oriented programming is a paradigm based on encapsulating logic and data into objects, which may then contain fields and procedures. Many of the most widely used programming languages are based on OOP, making it a very important concept in modern programming.
Public
Public questions (free account) are common interview questions. They are great for practicing, or if you want to filter candidates using the classic problems.
User interface contains two types of user input controls: TextInput, which accepts all characters and NumericInput, which accepts only digits.
Implement the class TextInput that contains:
- Public method void add(char c) - adds the given character to the current value
- Public method String getValue() - returns the current value
Implement the class NumericInput that:
- Inherits from TextInput
- Overrides the add method so that each non-numeric character is ignored
For example, the following code should output "10":
TextInput input = new NumericInput();
input.add('1');
input.add('a');
input.add('0');
System.out.println(input.getValue());
Java SE 8
- Example case: java.lang.ClassCastException
- Adding various characters to TextInput: java.lang.NoSuchMethodException
- Adding numeric characters to NumericInput: java.lang.ClassCastException
- Adding various characters to NumericInput: java.lang.ClassCastException