Skip to content
Related Articles

Related Articles

Improve Article
Java | Functions | Question 1
  • Last Updated : 07 Jan, 2014

Output of following Java program?

class Main {
    public static void main(String args[]) {   
    int fun()
      return 20;

(A) 20
(B) compiler error
(C) 0
(D) garbage balue

Answer: (B)

Explanation: main() is a static method and fun() is a non-static method in class Main.

Like C++, in Java calling a non-static function inside a static function is not allowed

Quiz of this Question

My Personal Notes arrow_drop_up
Recommended Articles
Page :