TOTAL QS = 22Time [ 00 : 00 : 00 ]
00:00:00

Java Methods Basics Online Test 1

Instructions

Total Questions: 22

Total Minutes: 22

This ExamTray Free Online Test or Quiz or Trivia tests your Programming Skills on basics of Java Methods. This test displays answers after finishing the exam for review. You can easily clear Competitive Exams and Job Interview Questions. Students can learn Java basics.

Go through Java Theory Notes on Methods before attempting this test.

All the Best

Challenge SCORE

0 / 22

Take This Exam
1) A Java method is comparable to a __ in c language.
2) All Java methods must have a return type. (TRUE / FALSE)
3) State TRUE or FALSE. A Java method can have the same name as the class name.
4) in Java, add a ___ to a constructor to convert it into a method.
5) Java method signature is a combination of ___.
6) In Java, a method name can not start with a ___.
7) In Java, a method name can start with ___.
8) In Java, a method name can contain numbers from 2nd character onwards. (TRUE / FALSE).
9) Choose the correct identifier for a method name in Java.
10) What is the output of the below Java program with an empty return statement?
public class TestingMethods2
{
  void show()
  {
    System.out.println("SHOW Method..");
    return;
  }
  public static void main(String[] args)
  {
    TestingMethods2 t2 = new TestingMethods2();
    t2.show();
  }
}
11) What is the output of the below Java program with a void method?
public class TestingMethods3
{
  void show2()
  {
    System.out.println("SHOW Method 2");
  }
  public static void main(String[] args)
  {
    TestingMethods3 t3 = new TestingMethods3();
    t3.show2();
  }
}
12) A "this" operator used inside a Java method refers to ___ variable.
13) What is the output of the below Java program with a "this" operator?
public class TestingMethods4
{
  int cakes=5;
  void order(int cakes)
  {
    this.cakes = cakes;
  }
  public static void main(String[] args)
  {
    TestingMethods4 t4 = new TestingMethods4();
    t4.order(10);
    System.out.println("CAKES=" + t4.cakes);
  }
}
14) A local variable declared inside a method can not be used in expressions without initializing it first. (TRUE / FALSE).
15) What is the output of the below Java program?
public class TestingMethods5
{
  public static void main(String[] args)
  {
    int localVariable;
    System.out.println(localVariable);
  }
}
16) In Java, local variables are stored in __ memory and instance variables are stored in ___ memory.
17) A static-method or a static-variable is shared among all instances of a class. (TRUE / FALSE)
18) What is the output of the Java program with static variables?
public class TestingMethods6
{
  static int cats=25;
  public static void main(String[] args)
  {
    TestingMethods6 t6 = new TestingMethods6();
    System.out.println("t6 BIRDS before=" + t6.cats);
    TestingMethods6 t7 = new TestingMethods6();
    t7.cats = 10;
    System.out.println("t6 BIRDS after=" + t6.cats);
  }
}
19) What is the output of the below Java program with a final local variable?
public class TestingMethods8
{
  int cars = 20;
  void change(final int cars)
  {
    cars = 10;
    this.cars = cars;
  }
  public static void main(String[] args)
  {
    TestingMethods8 t8 = new TestingMethods8();
    t8.change(30);
    System.out.println(t8.cars);
  }
}
20) Java does not allow nesting of methods. (TRUE / FALSE)
21) What is the output of the below Java program?
class Road
{
  static void show()
  {
    System.out.println("Inside static method.");
  }
}

public class TestingMethods10
{
  public static void main(String[] args)
  {
    Road.show();
  }
}
22) What is the output of the below Java program?
class SomeClass
{
  char batch = 'A';
}

public class TestingMethods11
{
  public static void main(String[] args)
  {
    SomeClass a1 = new SomeClass();
    System.out.println("Before: " + a1.batch);
    SomeClass a2 = new SomeClass();
    a2.batch = 'B';
    System.out.println("After: " + a1.batch);
  }
}

Open Certification Helper Popup Reset Popup