QUESTIONS ABOUT JAVA PROGRAMMING 1) Write a valid class header with public acces
ID: 643681 • Letter: Q
Question
QUESTIONS ABOUT JAVA PROGRAMMING
1) Write a valid class header with public access. Assign a legal identifier of your choice. Then write the body of the class that contains one data field named myPractice with a data type of double. Be sure to include any necessary curly braces and semicolons.
2) In the following code, what are the parameter data type and parameter identifier? How do you identify each?
3) Does a programmer need to write every class he or she uses? Why or why not?
4) Explain the purpose of a return type of a method. Describe the return value of a method that returns no data.
QUESTIONS ABOUT JAVA PROGRAMMING 1) Write a valid class header with public access. Assign a legal identifier of your choice. Then write the body of the class that contains one data field named myPractice with a data type of double. Be sure to include any necessary curly braces and semicolons. 2) In the following code, what are the parameter data type and parameter identifier? How do you identify each? 3) Does a programmer need to write every class he or she uses? Why or why not? 4) Explain the purpose of a return type of a method. Describe the return value of a method that returns no data.Explanation / Answer
1) Write a valid class header with public access. Assign a legal identifier of your choice.
Then write the body of the class that contains one data field named myPractice with a data type of double.
Be sure to include any necessary curly braces and semicolons.
Ans:
public class MyClass
{
private double myPractice;
}
Explanation:
The class must start with an Upeer Case letter Hence MyClass is a legal identifier.
Coming to myPractice , all class varibles recommended to declare as private.
Sometimes protected depends on your requirment.
=============================================================================
2) In the following code, what are the parameter data type and parameter identifier? How do you identify each?
Ans:
In the given code parameter datatype is double.
and parameter identifier is salary.
Explanation:
Generally the paramter for a function are identified by the arguments of function.
Here in this case the funtion has only one parameter salary and it is declared as type double.
=============================================================================
3) Does a programmer need to write every class he or she uses? Why or why not?
Ans:
If it is not present in Java packages then you have to write your own class.
For example Java provides ArrayList , You can directly import the ArrayList from util
package and you can use it rather than creating your own class.
So , Its depends on your class constrians and requirement, Hence Its always
better to use exisiting classes and import it in your program.
=============================================================================
4) Explain the purpose of a return type of a method. Describe the return value of a method that returns no data.
Ans:
Return type of a method is used to return a value which can be any primitive data type like int ,float or double or char.
And also can return user defined datatypes like Objects and ArrayList etc.
Hence, Sometimes return type is required depends on your function.
for example average of array elements you function should have the return type with double.
And for the method which doest not return anything thre return value is void.
for example priting a message using function does not have any return type.
=============================================================================