Java Methods

Here are 10 essential multiple-choice questions on Java Methods, covering key concepts.

Last Updated :
Discuss
Comments

Question 1

Which of the following is true about methods in Java?

  • A method must return a value.

  • Methods can only be static.

  • Methods can be parameterized.

  • Methods cannot have the same name in a class.

Question 2

What is the default return type of a method in Java if none is specified?


  • void

  • int

  • Object

  • Compilation error

Question 3

What will be the output of the following code?

Java
class Test {
    static void display() {
        System.out.println("Static Method");
    }
    public static void main(String[] args) {
        Test.display();
    }
}


  • Static Method

  • Compilation error

  • Null

  • Runtime error

Question 4

Which statement about instance methods is correct?

  • They can only be accessed from static methods.

  • They require an object to be called.

  • They are automatically synchronized.

  • They must be declared final.

Question 5

What happens if we declare a method both static and final?


  • Compilation error

  • The method cannot be overridden

  • The method can be overridden

  • Runtime error


Question 6

Identify the correct way to call a non-static method inside main().

  • methodName();

  • this.methodName();


  • new ClassName().methodName();

  • ClassName.methodName();


Question 7

What will happen when calling a static method using an object?

Java
class Demo {
    static void show() {
        System.out.println("Static Method");
    }
    public static void main(String[] args) {
        Demo obj = new Demo();
        obj.show();
    }
}


  • Compilation error


  • Static Method

  • NullPointerException

  • Runtime error

Question 8

What is the correct return type for a constructor in Java?

  • void


  • The class name

  • No return type

  • Object


Question 9

What happens if a static method tries to access an instance variable?


  • It accesses the instance variable normally

  • It throws an exception

  • It results in a compilation error

  • It works if the variable is final

Question 10

What is method overloading?


  • Two methods with the same name and parameters

  • Two methods with the same name but different parameters

  • Two methods with the same name but different return types

  • Defining methods inside a loop


There are 10 questions to complete.

Take a part in the ongoing discussion