Accessing A Function

The methods are the main building blocks of Java programs. A Java method is a collection of statements that is grouped together to perform an operation. The methods allow us to reuse the portion of code. When a method is defined at any place in the program, then it is called method definition. A simple Java method requires a minimum of three items: visibility - public, private, protected, Return Type - void, int, double, (etc.) and name of the method. A method is called (invoked or executed) by providing the method name along with the argument list enclosed in the parenthesis.

A parameter is a value that is passed to a method so that the method can use that value in its processing. The parameters are of two types: Actual parameter and formal parameters. The parameters that appear in function call statement are called actual parameters. The parameters that appear in method definition are called formal parameters. There are two ways for passing argument to the method: Pass By Value or Call By Value and Pass By Reference or Call By Reference.

To Access the full content, Please Purchase

  • Q1

    What is a public method?

    Marks:1
    Answer:

    A method which can be called by any object is a public method.

    View Answer
  • Q2

    Which keyword is used to declare a Java Class?

    Marks:1
    Answer:

    Keyword used is class.

    View Answer
  • Q3

    What is a local variable?

    Marks:1
    Answer:

    Variables declared inside an opening curly brace and a terminating curly brace are termed as local variables. Methods often store its temporary state in local variables.

    View Answer
  • Q4

    Explain the difference between local variable and global variable.

    Marks:4
    Answer:

    Variables that are declared inside an opening curly brace and a terminating curly brace are termed as local variables.

    Global variables are the variables that are known throughout the program and may be used by any part of the program. They hold their value throughout the execution of the program.

    View Answer
  • Q5

    Differentiate between formal and actual variable.

    Marks:4
    Answer:

    Formal variables are list of variables that will accept different types of values being supplied to the function by the calling program. Formal parameters are declared after the function name and inside parenthesis.

    The variables, which are associated with function name during function call, are called actual variables.

    View Answer