Prerequisite: null in Java, Static in Java
// Java program to illustrate calling // static method using Null public class GFG { public static void fun() { System.out.println("Welcome to GeeksforGeeks!!"); } public static void main(String[] args) { ((GFG)null).fun(); } }
Output:
Welcome to GeeksforGeeks!!
Explanation:
This program looks as if it needs to throw a NullPointerException. However, the most method invokes the greet method (fun) on the constant null, and you can’t invoke a way on null.
But, once you run the program, it prints “Welcome to GeeksforGeeks!!”. Let’s see how:
Australia
UK
UAE
Singapore
Canada
New
Zealand
Malaysia
USA
India
South
Africa
Ireland
Saudi
Arab
Qatar
Kuwait
Hongkong
Copyright 2016-2023 www.programmingshark.com - All Rights Reserved.
Disclaimer : Any type of help and guidance service given by us is just for reference purpose. We never ask any of our clients to submit our solution guide as it is, anywhere.