3. User-defined Methods

Lesson 2

Theories

Uses of Methods

  1. What are the uses of a method? Explain briefly.

Demo Program to Show the Uses

  1. Find total area of two rectangles.

Definition, Syntax and Example

  1. Define method.
  1. Write syntax and example of method definition.

Method Prototype / Method Header

  1. Define method prototype with syntax and example.

The Access Specifiers / Visibility Modifiers

  1. Define access specifiers (visibility modifiers)?

Diagrammatic Representation of Packages

  1. Which are the four accessibilities? Describe briefly each of them.

The static Modifier

  1. Define static modifier

A Program to Demonstrate Use of static Keyword

  1. Define a class Student. The name and totalMarks of each student are different. The totalSubjects (number of subjects) is same to all students. Create two Student objects and input values of the objects.

Diagramatic Representation of Objects

Two Types of Methods

There are two kinds of methods considering memory allocation.
They are member methods (instance methods) and class methods (static methods).
Example of member method: public void area() (Note: There is no static keyword.)
Example of class method: public static void area() (Note: There is static keyword.)

Member Method

  1. Describe briefly about member method.

Class Method / Non-member method / static method

  1. Describe briefly about class method.

Four Kinds of Variables

  1. Which are the four kinds of variables?

Instance Variable / Data Member / Member Variable / Attributes / Characteristics

  1. Describe briefly about instance variable.

Class Variable (Static variable)

  1. Describe briefly class variable.

Local Variable

  1. Describe briefly about local variable

Argument Variable

  1. Describe briefly about argument variables

Static Scanner Object

  1. What is the use of static Scanner object

Return Type

  1. What is meant by return type?

void Method

  1. What is a void method?

Method Name

  1. What is the use of method name?

Rules for Method Name

  1. What are the care to be taken when a method is named

Conventions

  1. What are the conventions when writing method names?

Parameters

  1. What is meant by parameters?

Actual Parameter and Formal Parameter

  1. Describe actual parameter and formal parameter.
  1. Is it necessary same variable names must be in actual parameter and formal parameter?

Method Signature

  1. What is a method signature? Write syntax with an example.

The Method Body

  1. Define method body.

The return Statement

  1. What is a return statement?
  1. Examples of various return statements.
  1. How many values can be returned from a method?

Method Call

  1. What is a method call? Write syntax and example.
  1. What is the care should be taken when a method returns a value?
  1. What is the care should be taken when a method is void type?

Call By Value

  1. What is call by value? Describe it with an example.

Call By Reference

  1. What is call by reference? Describe it with an example.
  1. Differentiate between Call By Value and Call By Reference.
  1. Arguments to the methods can be of two kinds. Which are they?
  1. How primitive values and objects and arrays are passed to methods?
  1. What is the advantage of call by value?
  1. What is the advantage of call by reference?

Pure and Impure Methods

  1. What is a pure method?
  1. What is an impure method?
  1. What is a modifier method?

Three Categories of Methods Considering Return Value

  1. Which are the three categories of methods based on returning of values?

Various Categorizations of Methods

  1. Which are the various categorizations of methods?

Method Overloading

  1. What is method overloading? Illustrate with an example.
  1. How does a method call distinguish its method definition when method names are same?
  1. What is the role of return type of method in method overloading?
  1. How the method overloading become an important part of the OOP?

Additional Questions

Method Prototypes

  1. Define a prototype for method named direction() that receives a character from NEWS as argument and returns the name of direction.
  1. Write a method prototype for a method named response to receive true or false from main() and returns “Yes” or “No”.
  1. Write a method prototype for a method named join to receive a word w and a sentence s from main() and returns the joined string str i.e., word follows sentence.

Method Dfenitions

  1. Define a method named direction() that receives a character from NEWS as argument and returns the name of direction. Use switch statement.
  1. Write a method named response to receive true or false as argument and returns “Yes” or “No”.
  1. Write a method named join to receive a word w and a sentence s from main() and returns the joined string str i.e., word follows sentence.