Page 230 - ComputerScience_Class_11
P. 230
C. Answer the following questions:
1. What are the three categories of statements?
Ans. The three categories of statements are:
1. Expression Statements
2. Declaration Statements
3. Control Statements
2. What are compound statements?
Ans. When a group of statements is written within a curly bracket, then it is known as a compound statement.
3. Which statement checks a particular condition?
Ans. The if statement checks a particular condition, when the condition is satisfied, then the statement/statements inside the "if" will
be executed.
4. What are the different types of conditional Statements?
Ans. The different types of conditional statements are as follows:
• if statement • if-else statement
• if and only if statement • if-else-if statement
• nested if statement • switch case
5. What is switch case?
Ans. Switch is a multiple-branch selection statement. It has a variable that is used to select from multiple case statements.
6. Define Fall Through situation? Write an example.
Ans. The moving of control from one case to another case in the absence of a “break” statement is known as Fall Through.
Example,
switch(ch)
{
case 1: System.out.println(5+6);
case 2: System.out.println(5-4);
break;
case 3: System.out.println(5*4);
default: System.out.println(5.0/6.0);
}
7. Explain the different types of statements in Java. Provide examples for each type.
Ans. In Java, there are three main types of statements:
Expression Statements: These statements consist of an expression that calculates certain equations and produces a result.
They may involve calculations such as a+b, 4*(4%2), etc. or expressions that modify the value of a variable in a program such
as a++, --b or even int add=a+b;
Declaration Statements: These statements are used to declare what type of data the variables or constants will contain.
For example,
int sum; double pi; boolean flag; char ch;
int sum=0; double pi=3.14; boolean flag=true; char ch='a';
Control Statements: These statements are used to decide in which direction the program will execute. There are mainly four types
of control statements. They are Sequential statements, Conditional statements, Iterative statements and Jump statements.
8. Describe the concept of scope of variables in Java.
Ans. In Java, variables are only accessible inside the part of the program where they are created. This is called the scope of a variable.
It defines the visibility and accessibility of a variable. There are two places in a program where the variables can be created. They
are created directly under a class as data members or inside a method as local variables.
Now, if a variable is created under a class, the data members can be accessed from anywhere in the class whereas if it is created
as a local variable, then it can only be accessed within the method it is created and will have no existence outside the method. If
a local variable is used outside the method it is created, the program will produce an error.
228 Touchpad Computer Science (Ver. 3.0)-XI

