(a) Operators with higher precedence are evaluated before operators with relatively lower precedence. Arrange the operators given below in order of higher precedence to lower precedence:
- (a)&&
- (b)%
- (c)>=
- (d)++
Show SolutionHide Solution↓
++
%
>=
&&
(b) Identify the statements listed below as assignment, increment, method invocation or object creation statements.
- System.out.println("Java");
- costPrice = 457.50;
- Car hybrid = new Car();
- petrolPrice++;
- Method Invocation
- Assignment
- Object Creation
- Increment
(c) Give two differences between the switch statement and the if-else statement
| switch | if-else |
|---|---|
| switch can only test if the expression is equal to any of its case constants | if-else can test for any boolean expression like less than, greater than, equal to, not equal to, etc. |
| It is a multiple branching flow of control statement | It is a bi-directional flow of control statement |
(d) What is an infinite loop? Write an infinite loop statement.
A loop which continues iterating indefinitely and never stops is termed as infinite loop. Below is an example of infinite loop:
for (;;)
System.out.println("Infinite Loop");
(e) What is constructor? When is it invoked?
A constructor is a member method that is written with the same name as the class name and is used to initialize the data members or instance variables. A constructor does not have a return type. It is invoked at the time of creating any object of the class.