(a) What is the difference between an object and a class?
Show SolutionHide Solution↓
A class is a blue print that represents a set of objects that share common characteristics and behaviour whereas an object is a specific instance of a class having a specific identity, specific characteristics and specific behaviour.
(b) What does the token 'keyword' refer to in the context of Java? Give an example for keyword.
Keywords are reserved words that have a special meaning for the Java compiler. Java compiler reserves these words for its own use so Keywords cannot be used as identifiers. An example of keyword is class.
(c) State the difference between entry controlled loop and exit controlled loop.
| Entry controlled loop | Exit controlled loop |
|---|---|
| It checks the condition at the time of entry. Only if the condition is true, the program control enters the body of the loop. | It checks the condition after executing its body. If the condition is true, loop will perform the next iteration otherwise program control will move out of the loop. |
| Loop does not execute at all if the condition is false. | The loop executes at least once even if the condition is false. |
| Example: for and while loops | Example: do-while loop |
(d) What are the two ways of invoking functions?
Two ways of invoking functions are:
- Pass by value.
- Pass by reference.
(e) What is the difference between / and % operators?
| / | % |
|---|---|
| Division operator | Modulus operator |
| Returns the quotient of division operation | Returns the remainder of division operation |
| Example: int a = 5 / 2; Here a will get the value of 2 which is the quotient of this division operation | Example: int b = 5 % 2; Here b will get the value of 1 which is the remainder of this division operation |