What will happen if the superclass method does not exist in the subclass while trying to override it?
- It will automatically create a new method in the subclass with the same name.
- It will lead to a compile-time error.
- It will result in a runtime error.
- It will use the superclass method without any issue.
In Java, when you try to override a method from a superclass in a subclass, the method in the superclass must exist; otherwise, it will lead to a compile-time error. Java enforces method signature matching during compile-time, so if the method doesn't exist in the superclass, the compiler will not find a method to override in the subclass, resulting in an error.
Loading...
Related Quiz
- Which of the following is an invalid variable name in Java?
- Which protocol is typically used to securely send data over the web?
- Imagine you are developing a real-time multiplayer online game where player data needs to be synchronized. What strategy and technology would you choose for networking communication?
- What is the default value of a local variable of data type boolean in Java?
- How do you specify a timeout while trying to connect to a remote socket?