EX 5-1
1.) The different between a class and an object is an object is a runtime entity that contains data and responds to message and a class is a software package or template that describes the characteristics of similar objects.
2.) The object will then be deleat by memory stage.
3.) The three important characteristics of an objects are behavior, state amd identity.
4.) The client and server are the two objects that involved when messages are sent. The relationship between them are a client’s interactions with a server are limited to sending a message.
5.) The class’s interface remains the same thing as the class’s implementation details, both of them can be changed radically without affecting any of its clients.
EX 5-2
1.) Messages that change an object’s state are called mutators. The accessors is another messages to access the object’s state if the mutators worked correctly.
2.) Private; specify that data or method to only be used in certain cirtaintance, within {}.
Public: the data or imformation after such a modifier can be seen or used by anybody and anywhere.
3.) A constructor methods is one or more methods that indicate how to initialize a new object.
4.) It can returns a string containing the student’s name and test scores.
5.) First, assign the variables an initial values.
Then set the object’s data attributes by sending the same message.
Additionally, we must add a object will variable 2.
Last, the variable 1 and 2 is refer to the same object.
6.) The different between the primitive types and the reference types are in memory. The primitive type’s variable is best viewed as a box that contains a value of that primitive type. A variable of a reference type is thought of as a box that contains a pointer to an object.
The example for the primitive type is (int, double).
The example for the reference type is (allclasses, for instance).
7.) A special value that indicates that no objects can be accessed.
8.) When a program attempts to run a method with an object that is null, Java throws a null pointer exception.
=>String str = null;
System.out.println (str.length());
9.) Default Constructors is what we have been so far have had empty parameter lists, this constructor initializes numeric variables to zero and object variables to null, thus indicating that the object variables currently reference no objects.
10.) If a class tmplate contains no constructers, the JVM provides a primitive default constructor behind the scence, This constructor initializes numeric variables to zero and object variables to null, thus indicating the object variables currently reference no objects.
11.) A class can include more than one constructor, provided each has a unidue parameter list, but all the constructors must have the same name, that is , the name of the class.
EX 5-4
1.)Formal parameter is parameter that listed in a method’s definition. Actual parameter is values passed to a method when it is invoked.
2.) When a method is called, the value of the actual parameter is automatically transfered to the corresponding formal parameter immediately before the method is activated.
3.) public the Sum(){
int sum;
sum = (int) Math.round (a + b);
debug(“Sum; “average);
retirn sum;
}
4.) It is convenient to achive temporary working storage for data in a method.
EX 5-5
1.) The lifetime of a variable is the period during which it can be used. Local variable amd formal parameters exist during a single execution of a method, once the method stops executing, the formal parameters and local variables are no longer accessible. Instance variable are last for the lifetime of an object, it avaliable every time a message is sent to the object and serve as the object’s memory, when the object stops existing, the instancce variables dsiappear as well.
2.) Shadowing is considered a dangerous programming practice because it greatly increase the likelihood of making a coding error.
Example=>iAmAVariable = iAmAVeriable;
The local variablee iAmAVariable is said to shadow the global variable with the same name.