0% found this document useful (0 votes)
4 views1 page

2.tutorial Questions

The document outlines four programming scenarios involving static and instance methods. Scenario 1 requires a static method in the MessageUtility class to print a greeting message. Scenarios 2, 3, and 4 involve creating methods for a basic calculator, a counter, and a circle class, respectively, focusing on returning values and modifying internal states.

Uploaded by

tuladega
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
4 views1 page

2.tutorial Questions

The document outlines four programming scenarios involving static and instance methods. Scenario 1 requires a static method in the MessageUtility class to print a greeting message. Scenarios 2, 3, and 4 involve creating methods for a basic calculator, a counter, and a circle class, respectively, focusing on returning values and modifying internal states.

Uploaded by

tuladega
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd

TUTORIAL QUESTIONS

Scenario 1 (Static method with void return type):

You need to create a utility method in a class called MessageUtility that


simply prints a greeting message to the console. The message should always
be "Welcome to our application!". Write the code for this static method,
ensuring it has a void return type.

Scenario 2 (Static method with a non-void return type):

You are writing a basic calculator. Create a static method within a class called
MathOperations that takes two integer numbers as input (you don't need to
define the parameters in the question, just describe the method). This
method should calculate the product of the two numbers and return the
result as an integer.

Scenario 3 (Instance method with void return type):

Imagine you have a class called Counter. Each object of this class should
have a method called incrementCount. This method should increase an
internal counter (you don't need to declare the instance variable in the
question) by one and then print the current value of the counter to the
console. Write the code for this instance method.

Scenario 4 (Instance method with a non-void return type):

You have a class called Circle that represents a circle. Each Circle object
might have a radius (you don't need to declare the instance variable). Create
an instance method called getArea within the Circle class. This method
should calculate the area of the circle (using a fixed value for PI within the
method) and return the calculated area as a double.

You might also like