adplus-dvertising

Welcome to the Classes and Methods MCQs Page

Dive deep into the fascinating world of Classes and Methods with our comprehensive set of Multiple-Choice Questions (MCQs). This page is dedicated to exploring the fundamental concepts and intricacies of Classes and Methods, a crucial aspect of Java Programming. In this section, you will encounter a diverse range of MCQs that cover various aspects of Classes and Methods, from the basic principles to advanced topics. Each question is thoughtfully crafted to challenge your knowledge and deepen your understanding of this critical subcategory within Java Programming.

frame-decoration

Check out the MCQs below to embark on an enriching journey through Classes and Methods. Test your knowledge, expand your horizons, and solidify your grasp on this vital area of Java Programming.

Note: Each MCQ comes with multiple answer choices. Select the most appropriate option and test your understanding of Classes and Methods. You can click on an option to test your knowledge before viewing the solution for a MCQ. Happy learning!

Classes and Methods MCQs | Page 22 of 30

Explore more Topics under Java Programming

Q211.
A "this" operator used inside a Java method refers to ___ variable.
Discuss
Answer: (c).Instance variable
Q212.
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);
  }
}
Discuss
Answer: (c).CAKES=10
Q213.
A local variable declared inside a method can not be used in expressions without initializing it first. (TRUE / FALSE).
Discuss
Answer: (a).TRUE
Q214.
What is the output of the below Java program?
public class TestingMethods5
{
  public static void main(String[] args)
  {
    int localVariable;
    System.out.println(localVariable);
  }
}
Discuss
Answer: (d).Compiler error
Q215.
In Java, local variables are stored in __ memory and instance variables are stored in ___ memory.
Discuss
Answer: (c).Stack, Heap
Q216.
A static-method or a static-variable is shared among all instances of a class. (TRUE / FALSE)
Discuss
Answer: (a).TRUE
Q217.
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);
  }
}
Discuss
Answer: (b).t6 BIRDS before=25
t6 BIRDS after=10
Q218.
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);
  }
}
Discuss
Answer: (d).Compiler error
Q219.
Java does not allow nesting of methods. (TRUE / FALSE)
Discuss
Answer: (a).TRUE
Q220.
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();
  }
}
Discuss
Answer: (a).Inside static method.

Suggested Topics

Are you eager to expand your knowledge beyond Java Programming? We've curated a selection of related categories that you might find intriguing.

Click on the categories below to discover a wealth of MCQs and enrich your understanding of Computer Science. Happy exploring!