Methods in Java MCQ Quiz – (Basics of Method)

This Java Quiz is based on Methods in Java basics MCQs. You can also attempt the previous Selection Statements in Java MCQ Quiz or Next Methods in Java mid level MCQ Quiz

1264

What is a method in Java?

A method is a block of code or collection of statements or a set of codes grouped together to perform a certain task or operation. It is used to achieve the reusability of code. We write a method once and use it many times. We do not require to write code again and again. It also provides the easy modification and readability of code, just by adding or removing a chunk of code. The method is executed only when we call or invoke it.

The most important method in Java is the main() method.

Method Declaration

The method declaration provides information about method attributes, such as visibility, return type, name, and arguments. It has six components that are known as method header, as we have shown in the following figure.

Method Signature: Every method has a method signature. It is a part of the method declaration. It includes the method name and parameter list.

Access Specifier: The access specifier or modifier is the access type of the method. It specifies the visibility of the method. Java provides four types of access specifiers:

  • Public: The method is accessible by all classes when we use a public specifier in our application.
  • Private: When we use a private access specifier, the method is accessible only in the classes in which it is defined.
  • Protected: When we use protected access specifier, the method is accessible within the same package or subclasses in a different package.
  • Default: When we do not use any access specifier in the method declaration, Java uses the default access specifier by default. It is visible only from the same package only.

Return Type: Return type is a data type that the method returns. It may have a primitive data type, object, collection, void, etc. If the method does not return anything, we use void keyword.

Method Name: It is a unique name that is used to define the name of a method. It must be corresponding to the functionality of the method. Suppose, if we are creating a method for subtraction of two numbers, the method name must be subtraction(). A method is invoked by its name.

Parameter List: It is the list of parameters separated by a comma and enclosed in the pair of parentheses. It contains the data type and variable name. If the method has no parameter, left the parentheses blank.

Method Body: It is a part of the method declaration. It contains all the actions to be performed. It is enclosed within a pair of curly braces.

Quiz Description: 

Name:  Methods in Java MCQ Quiz – (Basics of Method)

Subject:  Java

Topic: Methods

Questions: 15 Objective Type Questions

Time Allowed: 15 Minutes

Language: English

Important for:  B. Tech. / M. Tech. Students, B.Sc. / M.Sc. (CS / IT) and aspirants of I.E.S. and other competitive exams, computer science job interviews, Java job interviews, etc.

Created By: Esha Tripathi

Previous QuizSelection Statements in Java MCQ Quiz
Next QuizMethods in Java MCQ Quiz – (Mid Level)

4 COMMENTS

LEAVE A REPLY

Please enter your comment!
Please enter your name here