What is the output if we execute MainMethod4 class?
class Test
{
public static void main(String[] args)
{
System.out.println("parent main() method");
}
}
class MainMethod4 extends Test
{
}
/*
Output:- parent main() method
Explanation:- Inheritance concept is applicable for main() method. Hence while executing child class
if child class doesnot contain main() method then parent class main() method will be executed.
*/
{
public static void main(String[] args)
{
System.out.println("parent main() method");
}
}
class MainMethod4 extends Test
{
}
/*
Output:- parent main() method
Explanation:- Inheritance concept is applicable for main() method. Hence while executing child class
if child class doesnot contain main() method then parent class main() method will be executed.
*/
0 comments: