हिंदी

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 { and ends with a closing 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: int a = 10;

6. Example: { int a = 10; int b = 20; }

shaalaa.com
  क्या इस प्रश्न या उत्तर में कोई त्रुटि है?
अध्याय 7: Statements and their Scope - EXERCISE [पृष्ठ १६३]

APPEARS IN

धीरज मेहरोत्रा Computer Science [English] Class 12
अध्याय 7 Statements and their Scope
EXERCISE | Q 1. | पृष्ठ १६३
Advertisements
Share
Notifications



      Forgot password?
Use app×