Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

When answering the next 5 questions, consider the following code: comments and numbers indicate where additional code must be placed. public class MainClass { public

When answering the next 5 questions, consider the following code: comments and numbers indicate where additional code must be placed.

public class MainClass

{

public static void main(String[] args)

{

//(2) call the greeting methodof the MyClass class from here

//(3) creat a MyClass object called myObject

//(4) update myObject instance variables by calling an appropriate method

}

}

class MyClass

{

private int numOfItems;

private String reportTitle;

// (1)MyClass constructor goes here

public static void greetings()// note that greetings() is static

{

//greetings code goes here

}

public void update(int num, String title)

{

//update code goes here

}

public void print()

{

// print code goes here

}

}

  1. Suppose you are writing the constructor of theMyClassclass (1) Which of the following constructors is correct?

  1. public MyClass
  2. public void MyClass()
  3. public MyClass()
  4. public MyClass(void)
  5. public void MyClass

  1. Suppose you wish to call thegreetings() method that prints the greeting, at line (2) Which of the following statements will call this method correctly?

  1. MainClass.greetings();
  2. void result = greetings();
  3. myObject.greetings();
  4. greetings();
  5. MyClass.greetings();

  1. Suppose you wish to construct a MyClass object called myObject at line (3) Which of the following statements will correctly do this?

  1. MyClass myObject;
  2. myObject.MyClass();
  3. MyClass myObject = MyClass();
  4. MyClass myObject = new (MyClass);
  5. MyClass myObject = new MyClass();

  1. Suppose you wish to call the update method at line (4) Which of the following statements will call this method correctly? Assume the myObject object is available form question 3.

  1. update(myObject(3, "Hi!"));
  2. update(3, "Hi!");
  3. MyClass.myObject.update(3, "Hi!");
  4. myObject.update(3, "Hi!");
  5. MyClass.update(3, "Hi!");

  1. Here is the completedupdateThe intent of the method is to update the class' properties with the values provided by the parametersnumandtitle:

public void update(int num, String title)

{

int numOfItems = num;

reportTitle = title;

}

If this method is called, what can we say about the values of the class member variables (properties)numOfItemsandreportTitlewhen that call completes?

  1. Instance variable - numOfItems, takes on the value of num; reportTitle takes on the value of title.
  2. Instance variable - numOfItems, takes on the value of num; reportTitle's value remains unchanged.
  3. Instance variable - numOfItems, value remains unchanged; reportTitle takes on the value of title.
  4. Both instance variables - numOfItems' and reportTitle's values remain unchanged.
  5. A run-time error occurs because of the illegal redefinition of a variable inside the method.

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Modern Dental Assisting

Authors: Doni Bird, Debbie Robinson

13th Edition

978-0323624855, 0323624855

Students also viewed these Programming questions

Question

=+5 How does the market buy?

Answered: 1 week ago