Skip to the content
onlineexamguide
  • Home
  • Courses
  • Engg. Interview
    • Placement Papers
    • Electrical Engineering
    • Mechanical Engineering
    • Automobile Engineering
    • Civil Engineering
    • Computer Science Engineering
    • Chemical Engineering
    • CS & IT Engg.
      • C programming Tests
      • C++ programming Tests
      • Java Programming Tests
  • Online Exam
    • NTA UGC NET Exam
    • SSC Examination quiz
    • TET Examination Quiz
    • Banking Exam
    • Aptitude Tests
    • Computer Knowledge Tests
    • Logical Reasoning Tests
    • English Language Tests
    • Staff Nurse Exams
    • General Knowledge Tests
    • Networking Tests
  • Ghatna Chakra
  • Register
    • Instructor Registration
    • Student Registration
    • About us
    • Privacy Policy
  • Cart
  • User Login
  • Home
  • Courses
  • Engg. Interview
    • Placement Papers
    • Electrical Engineering
    • Mechanical Engineering
    • Automobile Engineering
    • Civil Engineering
    • Computer Science Engineering
    • Chemical Engineering
    • CS & IT Engg.
      • C programming Tests
      • C++ programming Tests
      • Java Programming Tests
  • Online Exam
    • NTA UGC NET Exam
    • SSC Examination quiz
    • TET Examination Quiz
    • Banking Exam
    • Aptitude Tests
    • Computer Knowledge Tests
    • Logical Reasoning Tests
    • English Language Tests
    • Staff Nurse Exams
    • General Knowledge Tests
    • Networking Tests
  • Ghatna Chakra
  • Register
    • Instructor Registration
    • Student Registration
    • About us
    • Privacy Policy
  • Cart
  • User Login

Methods in Java tutorial and Interview Questions and Answers

Methods in Java

Study and learn Interview MCQ Questions and Answers on Methods in Java . Attend job interviews easily with these Multiple Choice Questions

Methods in Java

Java Method Signature is nothing but a combination of Return-Type, Method’s Name and a Parameter list it accepts.

The method signature or syntax is as follows.

type METHODNAME(type param1, type param2..)
{
  //statements
  //..
  //return statement
}

Let us know about parts of Java Method Signature.

  1. Return Type
  2. Method Name
  3. Parameter List

1. Return Type: A Java method may or may not return a value. If it returns nothing, we specify it explicitly mentioning a “void” before it. A method can return primitive or Object type values.

2. Method Name: A Java Method Name can be a combination of Alphabets, Numbers and Special Symbols (Underscore and Dollar only).

Java Methods Naming Rules:

  • Method name can start with a Letter or Alphabet.
  • Method name can start with either Underscore(_) or Dollar($) symbol.
  • and Method name can not start with a number.
  • Method name can contain numbers in-between or at the end.
  • and Method name can not be a keyword.

3. Parameter List: Java methods can contain any number of parameters of any type. There can be zero parameters also. Variables which are part of a Parameter-list are also called Local Variables. Local variables are stored in Stack Memory. Also, the variables declared inside a method are also called Local Variables or Method Variables.

Naming Conventions or Rules for Local Variables:

  • Name of a Local variable can start with an Alphabet lowercase or uppercase. Lowercase is preferred.
  • Name of a Local variable can start with either an Underscore(_) or Dollar($) symbol.
  • and Name of a Local variable can not start with a number but it can contain numbers in-between or at the end.
  • Name can not be a keyword.
  • No two Local variables should have the same name.

An example Java program below explains how to pass arguments to a Java method and return values or objects from a method.

class Table
{
  int height;
}

public class JavaMethodExample
{	
  public static void main(String[] args)
  {
    JavaMethodExample je = new JavaMethodExample();
    Table t1 = new Table();
    t1.height = 10;
    je.show(t1); //Passing arguments to method

    int changedValue = je.increase(t1);
    System.out.println("New Height= " + changedValue);
    //System.out.println("New Height= " + t1.height); //This code also works
  }

  void show(Table tab) //Receiving parameters in method
  {
    System.out.println("Height= " + tab.height);
  }

  int increase(Table tab) //Returning a value
  {
    tab.height = tab.height + 20;
    return tab.height;
  }	

}
//OUTPUT
//Height= 10
//New Height= 30

Note

In the above example, the method “show” receives parameters. The method “increase” receives an object reference as a parameter and returns an integer value back to the calling method. Remember that “main” is also a method which is the starting point of program execution.

Share this Java Tutorial on Java Methods Signature Rules with your friends and colleagues to encourage authors

Methods in Java online test

[WpProQuiz 158]


For More Free online Quizzes of JAVA Programming Click here


For More Free online Quizzes of C Programming Click here

Write a comment Cancel reply

You must be logged in to post a comment.

Recent Posts

  • Atal Bihari Vajpayee | श्री अटल बिहारी वाजपेयी जीवन परिचय
  • सम्राट अशोक का जीवन परिचय (Emperor Ashoka)
  • Prithviraj Chauhan
  • बाल गंगाधर तिलक
  • स्वामी दयानंद सरस्वती
  • UPPSC Mines Inspector Recruitment 2022 Notification Out
  • AIIMS Delhi JR Vacancy 2022 [194 Post] Notification and Apply Online
  • भीमराव अम्बेडकर
  • डॉक्टर राजेंद्र प्रसाद का जीवन परिचय
  • श्रीनिवास रामानुजन का जीवन परिचय
  • Amnesty International day
  • World Economic Forum
  • UPSSSC VDO Syllabus and Exam Pattern 2022
  • RBI Officer Grade B Recruitment 2022
  • UKMSSB Assistant Professor Recruitment 2022 Apply Now 339 Post

About us

Free online test to practice for Competitive exams , Online Exam, Entrance and Interview. Learn and Practice online test for Free and Prepare for your exam online with us

Select Language

Follow us

Search

Learn and Earn

Register as Instructor - Create and sell online courses and coaching services with the best online platform onlineexamguide.com . Build a course, build a brand, earn money

Copyright © 2022 onlineexamguide.com - All Rights Reserved.
error: Content is protected !!

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.