August 28, 2007

Java Question -1

Q 1What do we call an operator that operates on only one operand?
A - An operator that operates on only one operand is called a unary operator.
Q 2- What do we call an operator that operates on two operands?
A - An operator that operates on two operands is called a binary operator.
Q 3- Is the minus sign a unary or a binary operator, or both? Explain your answer.
A - Both. As a binary operator, the minus sign causes its right operand to be subtracted from its left operand. As a unary operator, the minus sign causes the algebraic sign of the right operand to be changed.
Q 4- Describe operator overloading.
A - For those languages that support it (such as C++) operator overloading means that the programmer can redefine the behavior of an operator with respect to objects of a new type defined by that program.
Q5- Java programmers may overload operators: True or False?
A 5- False: Unfortunately, Java does not support operator overloading.
Q6 - Show the symbols used for the following operators in Java: assignment, not equal, addition,cast.
A - The above listed operators in order are: = != + (type)
Q7 - Is any operator automatically overloaded in Java? If so, identify it and describe its overloaded behavior.
A - The plus sign (+) is automatically overloaded in Java. The plus sign can be used to perform arithmetic addition. It can also be used to concatenate strings. However, the plus sign does more than concatenate strings. It also performs a conversion to String type. When the plus sign is used to concatenate strings, the operand on the right is automatically converted to a character string before being concatenated with the operand on the left. This assumes that the compiler knows enough about the operand on the right to be able to successfully perform the conversion. It has that knowledge for all of the primitive types and most or all of the built-in reference types.
Q8- What is the purpose of the cast operator?
A - The cast operator is used to purposely convert from one type to another.
Q9 - The increment operator is a binary operator: True or False?
A - False: The increment operator is a unary operator.

No comments:

Post a Comment