p.411.
3. implementing multiply() where the multiplier is a double
we will face the problem dealing with overloading.
5. (a)
6. (a)
8. (d)
p.419.
1. the actural parameter is the value itself
2. the formal parameter is the name of the value.
3. no.
7.
8. this() refer giving the value to 0
11. overloading mean, in java class there has more than one methods with the same name. so as long as the method has different parameters , the compiler choose the correct method based on the parameters provided in the method. While polymorphism, on true method can take an input parameter of more than one type. we can use simulate polymorphism through overloading, and we created separated method for each input.
14. compiler determine the correct method to use but overloaded method must have different parameters.
p.432
3. private void normalize()
{
dollars = dollars + cents / 100;
cents = cents % 100;
if (dollars > 0 && cents < 0)
{
dollars--;
cents = cents + 100;
}
else if (dollars < 0 && cents > 0)
{
dollars++;
cents = cents - 100;
}
}
// Instance variables
private int dollars;
private int cents;
p.442.
1. When we design a new class, we should try to make it work like a primitive type, such as int or double.. coz each primitive type has a complete set of operations for manipulating its values.
2. name for a set of values and set of operations we can perform on those values
4. e.g blance.add(); | balance.subtract();
7. because it's doesnt have getDollars(), getCents(), multiply(), less(), or equals() methods.
p.456
1. instance method can access the private variables of the objects
3. Humm. Both class methods and instance methods can access class variables, But class methods cant' access instance variables.
6. main() is class method, we can use class methods to organize the application class of a program. because we can define it as a public static method.
8. well this can be true for e.g int/0 but the programmer can prevent that kinda input give by user. promting the error message.
Posted by kj on [ 12:00 AM ]