0% found this document useful (0 votes)
152 views

Java Theory (9th Class)

The document provides notes on various topics related to programming concepts like OOP, data abstraction, encapsulation, polymorphism, inheritance etc. It also contains questions with answers on topics like features of OOP, benefits of OOP, limitations of different programming paradigms, how encapsulation is useful in OOP etc.

Uploaded by

Amazer Suvam
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
152 views

Java Theory (9th Class)

The document provides notes on various topics related to programming concepts like OOP, data abstraction, encapsulation, polymorphism, inheritance etc. It also contains questions with answers on topics like features of OOP, benefits of OOP, limitations of different programming paradigms, how encapsulation is useful in OOP etc.

Uploaded by

Amazer Suvam
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 13

Write short notes.

1) OOP - Object Oriented Programming is a modular approach which allows the data to be applied within a stipulated
program area. It also provides the reusability feature to develop productive logic and gives more emphasis on data.

2) Data abstraction – It is an act of representing essential features without including background details.

3) Encapsulation - It is a mechanism of wrapping data and functions into a single unit.

4) Machine Level Language – It is the form of computer language in which instruction are coded in terms of binary
digits i.e. 0s and 1s.

5) Polymorphism - It is a process of using a function or operator for more than one purposes.

6) Procedure Oriented Programming focuses on the functions rather than the data. The data values may keep floating
throughout the program in an insecure and unrestricted manner.

7) Inheritance – It is an OOP principle according to which a class acquires some features from another class.

8) Assembly Level Language – A language in which the instructions are coded in terms of mnemonics and
short forms is known as Assembly level language.

Distinguish between.
1) OOP and POP - Procedural Oriented Programming emphasizes on function rather than data. Data is not safe and
secure as it flows freely from function to function. It follows top-down approach.
Object Oriented Programming emphasizes on data rather than functions. Data is restricted to be used only by
authorized functions so data is safe and secure. It follows bottom-up approach.

2) HLL and LLL - High Level Languages are easy for human being to understand but computer does not understand
them directly. Translators are required to convert HLL to machine code. Low Level Languages are difficult for human
beings to understand but directly understood by computer. No translator is needed.

3) Compiler and Interpreter - Compiler converts the whole source code program into the object code at once. It
shows all errors in the program at once. Interpreter converts the source program into object code one line at a
time. It shows one error at a time.

Answer the following questions.

Q.1) What are the features of OOP?


Ans. Features of Object Oriented Programming are – It gives importance to data rather than functions. Data is
secured. It follows modular programming approach. It allows reusability of code.

Q.2) Write three benefits of OOP.


Ans. it is useful to solve complex program. It allows re-use of code. Data is safe and secure.

Q.3) Mention two limitations of POP and OOP.


a) Limitation of Procedure Oriented Programming - changes are not easy to implement. It is not suitable to
solve complex problem.
b) Limitation of Object Oriented Programming – it require intensive testing process. Solving problems is more time
consuming than Procedure Oriented Programming.

Q.4) How is Encapsulation useful in Object Oriented Programming?


Ans. Encapsulation is a mechanism of wrapping data and functions into a single unit. The data is kept hidden which
cannot be accessed directly outside the class but can be used within the program.

Q.5) What are the advantages of HLL?


Ans. It is machine independent language. It is easier to understand and code. Error detection and correction is
easier.

Answer the following questions.


Q.1) Who developed Java? What was it initially called?
Ans. James Gosling developed Java. It was initially called as Oak.

Q.2) Give a brief historical development of Java.


Ans. In 1991, James Gosling and his team at Sun Microsystems developed a language as a part of research work to
develop a language for consumer electronics. It was initially named as Oak but later in 1994 it was renamed as Java.

Q.3) Mention any four features of Java.


Ans. Four features of Java – It is an object oriented programming language. Java programs are both compiled and
interpreted. It can access data from local computer as well as from the Internet. It is case sensitive.

Q.4) Define byte code.


Ans. Byte code is an intermediate code generated when a Java source code program is compiled by the Java
compiler. It is further converted to machine code by the JVM.

Q.5) What is JVM?


Ans. Java Virtual Machine (JVM) is the Java Interpreter which converts Java Byte code to Machine code.

Q.6) Name any three packages of Java.


Ans. Three packages of Java are java.lang, java.io and java.util

Q.7) What are Java reserved words? Name any five of them.
Ans. Java reserved words are also known as keywords. These are the words which carry special meaning for
the compiler. Five keywords are – class, public, static, void, double etc.

Q.8) Distinguish between JDK and BlueJ.


Ans. JDK 1.3 is a DOS based or CUI based where as BlueJ is Window based or GUI based. JDK 1.3 is not user friendly
where as BlueJ is user friendly. JDK 1.3 is mandatory for Java programming whereas BlueJ is optional for Java
programming.

Q.9) A compiler is specific to a language. Explain.


Ans. A compiler is designed to compile a program written in a specific language, it can not compile program written in
any other language. For example the Java compiler can compile a program written in Java but not a program written
in Python or C++.
Q.10) What is the basic format of a Java program? Explain with an example.
Ans. The basic format or structure of Java program is as follows. Comment
Package activation Class
declaration
Declaration of main method Closing of
main method Closing of class block

Example:
//to display hello world
import java.lang.*;
class A
{
public static void main(String args[])
{
System.out.println(“Hello World”);
}
}

Q.11) What is BlueJ?


Ans. BlueJ is a Window based free software to write, debug and run Java programs easily. It is designed for
beginners to learn to do Java programming easily.

Q.12) Mention any five features of BlueJ.


Ans. Five features of BlueJ are –
It is Window based or GUI based. It is user
friendly and easy.
It is an IDE which provides a code editor, a debugger, and a viewer integrated in a single place.
It helps in easier debugging as error lines are highlighted and shown at the bottom of the window. It allows to
create objects of the class dynamically and invoking their methods and supplying data to those methods during
run time.

Q.13) Name the package that is activated by default.


Ans. java.lang

Q.14) What are the points to be taken care of while naming a class in a Java program?
Ans. The class name should not contain blank space. The class name should not be a keyword. The class name
should not start with a digit. No symbol other than $ and _ should be used.

Q.15) Java is case sensitive language. Explain.


Ans. Java is case sensitive means Java treats upper case letters and lower case letters as different.

Q.16) What is the significance of public, static and void?


Ans. In the statement public static void main(String args[]), public is access specifier, static is access modifier and
void is return type of main method.

Q.17) What does the term Compilation mean?


Ans. Compilation means to convert a source code to machine code.
Q.18) A Java program uses a compiler as well as an Interpreter.Explain.
Ans. A Java program uses both compiler and interpreter. It uses compiler to convert the source code to byte code
and an interpreter to convert byte code to machine code.

Answer the following questions.


Q.1) Define an Object with an example.
Ans. Object is an identifiable entity which has characteristics and behaviors. Example – cycle, car, mobile, book,
pen, etc.

Q.2) How will you define a software object?


Ans. A software object is an imaginary object created while writing a Java program. The characteristics and behaviors
of the real world objects are represented through member variables and member functions in software object.

Q.3) Class and Objects are inter-related. Explain.


Ans. A class is used to define objects and specifies its characters and behaviors. A class produces objects.
Objects are imagined through a class. So, both are inter-related.

Q.4) A class is also referred to as Object Factory. Explain.


Ans. A class designs objects and specifies their characteristics and behavior. A class is used to produce or create
various objects of same type. Hence, a class is called an object factory.

Q.5) What does the following statement mean?


Employee staff = new Employee();
Ans. Here an object named ‘staff’ is created from the class ‘Employee’.

Q.6) Why is an object called instance of a class? Explain.


Ans. Since an object possesses instance variables and member methods defined within the class, it is called an
instance of a class.

Q.7) Why is a class known as a composite data type?


Ans. A class is a tool to create user defined data types. The class name becomes the data type for the instances used
in the program. It is such a data type that includes various predefined data types within it. Hence, the class is said to
be a composite data type.

Q.8) Write a Java statement to create an object ‘keyboard’ of the class ‘Computer’.
Ans. Computer Keyboard = new Computer();

Write short answers.


Q.1) What do you mean by data types?
Ans. Data types are used to create variables. In Java, we need to deal with various types of data. Hence,
different data types are there to handle them.

Q.2) Define variable with example.


Ans. A variable is a named memory location in RAM, which stores a value that can be changed. For example int a,
where <a> is a variable of int data type that can hold an integer value.

Q.3) What do you mean by constant? Explain with an example.


Ans. Constants also called as Literals are data values which remain fixed or unchanged throughout the execution of
program. Example: 5, 0.5, -2, “Stewart”, false, ‘A’, etc.

Q.4) State two kinds of data types.


Ans. Primitive data type and Non – Primitive data types are two types of data types.

Q.5) What do you understand by token? Name different types of tokens.


Ans. Each individual component of a Java statement is known as token. Different types of tokens are Keywords,
Identifiers, Literals, Operators, Separators or Punctuators.

Q.6) What are the rules to assign a variable in Java?


Ans. <data type> <variable> = <constant>;

Q.7) Explain the term type casting?


Ans. Type casting is also known as explicit type conversion where a data type is forcibly converted to another
through user interference. There is a chance of loss of data in type casting.

Q.8) Distinguish between integer constant and floating constant.


Ans. Integer constants are numbers without decimal point like 5, 34, etc. whereas floating constants are
numbers with decimal point in it like 5.4, 0.4f.

Q.9) Distinguish between token and Identifier.


Ans. Each individual component of a Java statement is known as token whereas identifiers are names given to
different parts of program like variable names, class names, object names, method names, etc.

Q.10) Distinguish between character constant and string constant.


Ans. A single character kept in a pair of single quotes is called character constant whereas a group of characters
kept in a pair of double quotes is called string constant.

Q.11) Distinguish between character literal and Boolean literal


Ans. A single character kept in a pair of single quotes is called character constant whereas true and false are called as
Boolean constant.

Q.12) What do you understand by Boolean data type? Explain with an example.
Ans. Boolean data type is used to create variables which will store true or false. Boolean data type occupies 1 byte of
memory.

Q.13) What do you mean by primitive data type? Give two examples.
Ans. Primitive data types are inbuilt data types or system defined data types which come along with Java language.
There are eight primitive data types. int and double are two primitive data types.

Q.14) Why is it necessary to define data types in Java programming?


Ans. The compiler contains a phase called the storage assignment phase. This phase allocates memory for different
variables used in our program. It also creates the structure in the location to store the data efficiently. Hence the
compiler must know the type of data we are going to supply for storage to ensure optimum utilization of memory
space. This is the reason why data types are required while creating variables.
Q.15) Define implicit type conversion and explicit type conversion.
Ans. (a) implicit type conversion takes place internally and automatically. In a mixed expression, all lower data type
operands are automatically converted to the higher data type operand present in the expression.
(b) Explicit type conversion means the data type on an operand is forcibly converted to another through user
interference.

Q.16) Define Coercion.


Ans. Coercion is also known as implicit type conversion. It takes place internally and automatically. In a mixed
expression, all lower data type operands are automatically converted to the higher data type operand present in the
expression.

Q.17) What do you mean by type conversion? How is implicit type conversion different from explicit type conversion?
Ans. The change of the data type of an operand to another type is called as type conversion. Implicit type conversion
takes place internally and automatically. In a mixed expression, all lower data type operands are automatically
converted to the higher data type operand present in the expression.
Explicit type conversion means the data type on an operand is forcibly converted to another through user
interference.

Q.18) In what way is static declaration different from dynamic declaration?


Ans. Static initialization means to assign a value in a variable during compile time whereas dynamic initialization
means to assign a value in a variable during run time of the program.

Q.19) What do you mean by non-primitive data type? Give example.


Ans. Non-Primitive data types are user defined data types. They are not readily available or inbuilt data types in Java.
Rather they are created using various primitive data types through class keyword. So, they are also called as derived
data types or composite data types. Example of non-primitive data types are class, array, etc.

Answer the following questions.


Q.1) What are operators?
Ans. Operators are symbols used to perform various mathematical calculations and relational comparisons.
Examples of operators are +, -, *, I, %, >, >, etc.

Q.2) Name the different types of operators.


Ans. Different types of operators are: Arithmetic operators, Relational operators, Logical operators, Unary
operators, Binary operators, Ternary operators, Assignment operator, Shorthand assignment operators, etc.

Q.3) Explain Arithmetic operators, Relational operators, Logical operators, Unary operators, new operator and dot
operator.
Ans. Arithmetical operators are symbols used for mathematical calculations. Ex: +, –, *, /, %
Relational operators are symbols used for comparisons. They return boolean true or false. Examples:

>, <, >=, <=, ==, !=


Logical operators are symbols used to join two or more relational expressions. Examples: &&, ||, !

Unary operators are symbols that operate on a single operand. Examples: ++, – –, !, –, +

The new operator is used to create objects of a class. It allocates memory dynamically.

The dot operator (.) is used to access members of a class or of an object or of a package. It provides path.
Q.4) What is ternary operator? Write its syntax and explain it with an example.
Ans. Ternary operator deals with three operands. It is also called the conditional assignment operator. Because the
value assigned to a variable depends on the result of a condition.
Syntax: Variable = Condition? Expression1 : Expression2;
Here if the condition is true, then expression1 is assigned to the variable. If the condition is false, then expression2
is assigned to the variable.

Example: int a = 5 > 6? 4: 3;


Here 3 will be assigned to the variable a.

Q.5) Distinguish between the followings.


a) Binary operator and Ternary operator
b) && operator and || operator
c) Prefix operator and postfix operator
d) System.out.print() and System.out.println()

Ans.
a) Binary operators deal with two operands. Examples: +, –, *, /, %, >, <, >=, <=, ==, !=, =,etc. Ternary operators
deal with three operands. ? and : are Ternary operators.
b) Logical AND (&&) operator is used to combine two or more conditional expressions such that it results in true
if all the conditions are true, otherwise its result is false. Logical OR (||) operator is used to combine two or
more conditional expressions. It will result in true if any one or more condition is true, if all conditions are
false, it results in false.
c) When unary increment or decrement operator is used before the operand, it is known as prefix operator. The
value of the variable changes before the operation will take place. When the unary increment or decrement
operator is used after an operand, it is known post fix operator. It changes the value of the operand after
performing the operation.
d) System.out.print() statement displays the output on screen and keeps the cursor on the same line so that the next
output appears on the same line. System.out.println() statement displays the output on the screen and takes the
cursor to the next line so that the next output will appear on the next line.

Q.6) Differentiate between an operator and an expression.


Ans.6) An operator is a symbol which is used along with operands to build expression. An expression is a combination
of operands and operators arranged in a logical order to perform some work. Example of operators are +, –, *, /, %, >,
/, %, >, <, >=, <=, ==, =, etc. Example of expression is 5 + 4.

Q.7) Difference between = and ==.


Ans. = is assignment operator. It assigns a value to a variable. == is relational operator. It compares two operands
and returns true or false.

Q.3) Differentiate between.


1. nextInt() and nextFloat().
Ans. The nextInt() method of Scanner class is used to accept/receive an integer entered through keyboard during run
time and stores in a variable. The nextFloat() method of Scanner class is used to receive / accept a decimal value
entered through keyboard during run time and stores in a variable.
2. Syntax error and Logical error.
Ans. Syntax errors occur due to violation of rules and grammar of the language or due to typing mistakes. These errors
are shown during compile time and program does not execute until the errors are removed. Logical errors occur due to
wrong planning in program’s logic by programmer or due to using wrong method to solve a problem or due to use of
wrong operators. These errors are never shown and program gets executed but shows wrong output.

Answer the followings.


Q.1) Write down about Scanner class.
Ans. Scanner class is present in the java.util package. It contains many methods through which data can be accepted
during runtime. Some of the methods are nextLine(), nextInt(), nextDouble(), etc.

Q.2) What is the use of import?


Ans. import keyword is used to include a package in a program. It activates a package and links it with a program.

Q.3) What is a package?


Ans. A package is a collection of various pre-defined classes. These classes contain various functions which perform
various tasks. In order to use these functions, we need to include the package in our program. The keyword “import”
helps to include a package in a program. Example of packages: java.util and java.io

Q.4) Write a program to display square of a number.


Ans. class A
{
public static void main(int a)
{
int b = a * a;
System.out.println(“Number = “ + a + “ and its square = “ + b);
}
}

Q.5) What is diagnostic message?


Ans. A Diagnostic message indicates that something may be wrong with the program. It is shown by the compiler.
Diagnostical messages detect only syntax errors means there are pre-defined rules in Java language or syntax of writing
statements. If these rules or syntaxes are not followed then, the compiler can detect it and report these errors during
compile time. That’s why only syntax errors can be reported through Diagnostical messages.

Q.6) Write a statement to accept a character and store in a variable.


Ans. char ch = sc.next().charAt(0);

Q.7) Write down about run time errors.


Ans. Run time errors occur due to wrong data given as input during run time or due to incorrect mathematical
operations. These errors are shown during the execution of the program. Example of run time error is dividing a number
by zero.
Q.8) Name various types of errors?
Ans. Syntax error, Logical error and Run time error are the three types of error that may occur during execution of a
program.

Q.9) Distinguish between Testing and Debugging.


Ans. Testing is a process in which a program is validated. Testing is complete when all desired verifications against
specifications have been performed. Debugging is a process in which the errors are removed from the program.
Debugging is finished when there are no errors and the program is ready for execution.

Q.10) Explain the purpose of following Math functions.


Ans.1) Math.random() function returns a decimal number randomly which is greater than 0.0 and smaller than 1.0.
Ans.2) Math.max() function returns the greater number out of two given numbers.
Ans.3) Math.cbrt() function returns the cube root of a given number.
Ans.4) Math.abs() function returns the absolute value of a given number ignoring its sign.
Ans.5) Math.log() function returns the natural logarithmic value of a given number.

Q.11) Distinguish between.


a) Math.ceil() and Math.floor()
Math.ceil() function returns a higher or equivalent value of the given number. Ex – Math.ceil(2.4) = 3.0
Math.floor() function returns a lower or equivalent value of the given number. Ex – Math.floor(2.8) = 2.0

b) Math.round() and Math.rint()


Math.round() function is used to return the round off value of a given number. if the fractional part of a given number is
less than 0.5 then it returns the integer part of that given number otherwise it returns the next higher integer value. Its
return type is int. Ex – Math.round(2.5) = 3
Math.rint() function is also used to return the round off value of a given number. But its return type is double. If the
fractional part of a given number is within 0.0 to 0.5 then it returns the integer part of that given number in decimal
form otherwise it returns the next higher integer number in decimal form.
Ex – Math.rint(2.5) = 2.0 and Math.rint(2.51)=3.0

Answer the following questions.


Q.1) What are the different ways to manage flow of control in a program?
Ans.The different ways to manage the flow of control in a program are:
a) Normal flow of control (Sequential)
b) Conditional flow of control (Selection)
c) Iterative / Repetitive flow of control (Iteration / loop)

Q.2) Name two Selection statements.


Ans. (a) if else statement (b) switch case statement

Q.3) What is nested if? Explain with an example


Ans. The presence of one if statement within another if block is called nested if. The inner if statement will only be
checked when the outer if statement is evaluated to true otherwise not.
if(condition1)
{
if(condition2)
Statement1
else
Statement2

]
else
{
Statement3
}

Q.4) Write down about if else statement with an example.


Ans. if else statement is used to check a condition and to execute some statements when the condition is true and to
execute some other statements when the condition is false.
if(condition)
Statement1
else
Statement2

Q.5) Write down about if else if statement with an example.


Ans. if else if statement is used when more than two actions are to be taken. It checks one condition and it is true then
one action is taken otherwise another condition is checked and if that is true then second action is taken otherwise next
conditions are checked one by one and depending on the result of those conditions, any one action is taken.
if(condition1)
Action1
else if(condition2)
Action2
else if(condition3)
Action3
------------
------------
else
Last Action

Q.6) Distinguish between if else and switch case.


Ans. if else is a bi-directional branching statement whereas switch case is a multiple branching statement. Operators are
used to check condition in if else whereas no operator is used to check condition in switch case. float and double data
type constants/variables can be checked in if else but not in switch case.

Q.7)Write down about switch case.


Ans. A switch case is a multiple branching statement. It is used instead of writing multiple if else if statements. It is used
in menu driven programming.
Q.8) Write down about default statement.
Ans. A default statement is just like the else of if statement. The default statement executes when none of the case
value is matched with the switch variable. Use of default is optional in switch block.

Q.9) What is fall through? Why is break used?


Ans. In switch case, when any case value is matched with the switch variable, then statements in that case block are
executed and all other subsequent case blocks also get executed. This is called fall through. To prevent fall through to
happen, break keyword is used. The break keyword is a jump statement. It terminates the switch block and takes the
control out of it.

Q.10) What is fall through?


Ans.9) In switch case, when any case value is matched with the switch variable, then statements in that case block are
executed and all other subsequent case blocks also get executed. This is called fall through.

Q.11) What is a compound statement? Explain with an example.


Ans. A statement that contains one or more statements within its block is called a compound statement. In the following
example, if statement is a compound statement.
if(condition)
{
Statement1;
Statement2;
}

Q.12) In which situation the if else if statements are used?


Ans. The if else if statement is used when more than two actions are to be taken depending on conditions. It checks one
condition and it is true then one action is taken otherwise another condition is checked and if that is true then second
action is taken otherwise next conditions are checked one by one and depending on the result of those conditions, any
one action is taken.
if(condition1)
Action1
else if(condition2)
Action2
else if(condition3)
Action3
------------
------------
else
Last Action

Q.13) What is the use of System.exit(0)?


Ans. System.exit(0) will terminate the execution of a program in the middle of its execution. The remaining statements
in the program after System.exit(0) statement will not be executed.

Answer the following questions.


Q.1) What is iterative statement or loop?
Ans. When execution of the statements are repeated sequentially a number of times in a program, the process is known
as iterative process. A loop executes one or more statements repeatedly until the condition becomes false.

Q.2) Explain for loop with example.


Ans. A for loop executes one or more statements repeatedly until the condition becomes false. For Example the
following for loop displays a message ‘welcome’ 5 times.

int a;
for(a=1;a<=5;a++)
System.out.println(“Welcome”);

Q.3) Name different types of loops.


Ans. Entry control loop, Exit control loop, finite loop, infinite loop, delay loop or null loop, Fixed iterative loop, unfixed
iterative loop, continuous loop, step loop, etc. are the various types of loop.

Q.4) What are the parameters used in a for loop?


Ans. A for loop is designed with the help of three parameters such as initial value, test condition and update value. A for
loop can also execute omitting one or more parameters.

Q.5) Define entry control loop and exit control loop with example.
Ans. In entry control loop, the condition is first checked and then the loop executes. The loop may not execute even
once if the condition is false from the beginning. for and while are its example. In Exit control loop, the condition is
checked after executing the loop block. This loop will execute at least once even if the condition is false from the
beginning. do-while is its example.

Q.6) Write down the general format / syntax of a) for loop, b) while loop and c) do-while loop.
Ans.

a) for(initialization; test condition; updation)


{
Statements
}

b) initialization;
while(test condition)
{
statements
updation
}

c) Initialization
do
{
Statements
Updation

} while(test condition);
Q.7) Write down the use of break and continue in loop.
The break keyword is a jump statement. It is used to terminate a switch block or a loop and takes the control out of it
immediately skipping rest of the iteration of the loop or subsequent cases in the switch block unexecuted. The continue
keyword is a jump statement. It is used in a loop to skip its current iteration and go for the next iteration skipping
statements following it. It does not terminate the loop and keeps the loop running until the loop condition is false.

Q.8) What is inter-conversion of loops?


Inter-conversion of loops means converting a loop from one form to another. For example converting for loop to while
loop or to do-while loop and vice versa.

Q.9) Define finite loop, Delay loop, Infinite loop and Null loop.
Finite loop – When a loop block is executed for a fixed number of times, it is called a finite loop.
Delay loop – A null loop is used to delay the execution of the subsequent statements in the program. That’s why a null
loop is also called as delay loop.
Infinite loop – A loop which never ends and executes for ever is known as infinite loop.
Null loop – A loop that does not include any statement to be executed is known as null loop.

Q.10) Distinguish between for loop and while loop.


Ans. In for loop, the number of iteration is fixed. This looping construct is used when the number of iteration is known.
The while loop is categorized as unfixed iterative construct. It executes a set of statements till a given condition is true.
The number of iteration may not be known at beginning.

Q.11) Write one similarity and one difference between while and do while loop.
One similarity between while and do-while loop is both are categorized as unfixed iterative loops. One difference
between them is while is an entry control loop and do-while is an exit control loop.

Q.12) Write one similarity and one difference between while and for loop.
Ans. One similarity between while and for loop is both are categorized as entry control loops. One difference between
them is while loop is unfixed iterative loop and for loop is fixed iterative loop.

Q.13) Give one difference between Step loop and Continuous loop.
Ans. Step loop is a loop where the control variable is updated by a given value other than 1 after each iteration.
Continuous loop is a loop where the control variable is updated by 1.

Q.14) Name two jump statements and their uses.


Ans. Two jump statements are break and continue. The break statement is used to terminate a switch block or a loop
and takes the control out of it immediately skipping rest of the iterations of the loop or subsequent cases in the switch
block unexecuted. The keyword continue is used in a loop to skip its current iteration and go for the next iteration
skipping statements following it.

You might also like