Read: Objects First with Java: Complete chapter 1 Computer Exercises - Complete
ID: 3666158 • Letter: R
Question
Read: Objects First with Java: Complete chapter 1 Computer Exercises - Complete the exercises below. For questions from the book, please submit both the questions and answers. Exercises 1.30 - 1.35 (Questions and answers) Explain the following Java terms: Explain and compare these pairs of related words: Class, object Parameter ("formal parameter"), Argument ("actual parameter") Method signature What is it? What is it composed of? Write an example of your own. State of an object Source code Chapter 2 Read: Chapter 2 through p. 28 Computer Exercises: Submit the following attached to this assignment sheet: Examine the code for the naive-ticket-machine project. Write the names only of the: constructor fields methods Exercises 2.1 - 2.9. Note on submitting assignments... Attach all papers to the assignment sheet. Fill in the due date and the submission date if it's later.Explanation / Answer
Chapter 1
1. a
Class and Object
Class: Class is model or blue print that has properties and methods. A typical class has properties on which methods can call.
A class is a building block of an object -oriented language through communication of objects is possible.
Object: Object is created from a class is called instance of a class. Objects are able to call the methods of the class. Each object has its own state of instance variables.
The instance variables of class object are only can be modified using the methods of the class.
Classes will not create any memory but objects create memory of required variables encapsulated by object name.
b. formal parameter and actual parameter
Formal parameter: It is parameter passing technique that the formal parameters acts as place holders that take copy of the variables in method definition or the parameters written in the function definition can be called as formal parameters.
For example,
void swap(int num1, int num2)
{
//code follows
}
Where num1 and num2 are formal parameters
Actual parameter: The parameters called in function calling is called actual parameter.
int main()
{
//calling swap with acutal parameters 4 and 5
swap(4,5)
}
2. a
Method signature:
A method signature is the declaration of method definition.
A method definition has the following parts
Return type methodName(list of arguments)
b. Composition of method signature
A method defintion has the following parts
return type methodName(list of arguments)
------------------------------------------------------------------------------------------------------
c. signature of method in own words
Two methods with only return type different cannot be considered as two different methods.
if list of parameters are same , return type is different treats as same method signature.
For example,
int methodName(int a, int b);
void methodName(int a, int b); are both consider as same methods by compilers.
int methodName(int a, double b);
void methodName(int a, int b); are considered as different methods by compiler since argument list is different.
---------------------------------------------------------------------------
3. State of an object.
-------------------------------------------------------------------------------
4.
Source code:
Source code is program code that contains the instructions
in high level programming language.
//source code of java sample program
public class className
{
public static void main(sring[] args)
{
//code follows
}
}
Note : Chapter 2 naive ticket machine project is not given in post.
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.