🎴 Flashcard Mode
Java and Object-Oriented Programming Quiz
Card1 / 20
Mastered0
Review0
QuestionClick to flip
You have the following code in a file called Test.java class Base{ public static void main(String[] args){ System.out.println("Hello"); } } public class Test extends Base{} What will happen if you try to compile and run this?
AnswerClick to flip back
A
Compiles and runs printing "Hello"
💡 Explanation:
The code compiles and runs successfully because the main() method is inherited from the Base class. Even though Test extends Base, static methods are not inherited in the traditional sense - they belong to the class where they're defined. However, when you run 'java Test', it executes Base.main() which prints "Hello".