Differentiate between a statement and a block.
Advertisements
प्रश्न
Differentiate between a statement and a block.
Advertisements
उत्तर
|
Statement |
Block |
|---|---|
|
1. A statement is a single instruction that tells the Java program to perform a specific action. |
1. A block is a group of zero or more statements enclosed within curly braces { } and treated as a single unit. |
|
2. A statement generally performs an individual operation, such as assigning a value, declaring a variable, or calling a method. |
2. A block is used to group related statements that perform a particular task together. |
|
3. Simple statements in Java end with a semicolon |
3. A block begins with an opening curly brace |
|
4. A statement does not necessarily create a separate scope for variables. |
4. A block can define a separate scope for variables declared within it. |
|
5. A statement may be used independently or as part of a block. |
5. A block can contain multiple statements and may also contain nested blocks. |
|
6. Example: |
6. Example: |
