Question
a) (5 points) Check these two different ways of initializing instance variables. public class Option1 { private int a; public Option1() { a = 10;
a) (5 points) Check these two different ways of initializing instance variables.
public class Option1 { private int a; public Option1() { a = 10; } }
public class Option2 { private int a = 10; }
Discuss in your own words which way would you prefer to initialize instance variables. In which circumstances, Option 1 is preferred over Option 2? In which circumstances, Option 2 is preferred over Option 1? Cite if needed.
b) (5 points) Explain the purpose of a method parameter. What is the difference between a parameter and an argument? Cite if needed.
c) (5 points) What is the difference between a local variable and an instance variable (class attribute)? Cite if needed.
d) (5 points) Write a Java application that uses looping, if statements, and Math library (for absolute value and power) to print the following table of values (notice that N = 0 is skipped in the table):
N | 10*N | ABS(N) | N^2 |
-2 | -20 | 2 | 4 |
-1 | -10 | 1 | 1 |
1 | 10 | 1 | 1 |
2 | 20 | 2 | 4 |
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started