Page 108 - ComputerScience_Class_11
P. 108
System.out.println("Area is " ar);
}
}
In the above example, there are two syntax errors:
• calculate(int l, b), there is no "int" before b.
• System.out.println("Area is" ar); here before ar, there should be + to concatenate the two strings.
8. Write the differences between machine language and assembly language.
Ans. Machine Language Assembly Language
It is also known as machine code and is It is the beginning step to improve programming
directly understood by the computer. language as it makes programming language
more readable by programmers.
There is no requirement to translate it, as all It is made up of symbols and letters which are
the instructions are written in binary form translated into Machine language by a translator.
(i.e., strings of 0 and 1, e.g., 10111010110….).
D. Higher Order Thinking Skills (HOTS)
1. You are developing a school management system. The system needs to protect student data from being accessed directly by
other parts of the program. Explain which programming approach (POP or OOP) would be more suitable and why.
Ans. Object-oriented programming (OOP) would be more suitable. In OOP, data and methods are combined into a single unit called a
class using encapsulation. Data cannot be accessed directly from outside the class and can only be accessed through methods.
This ensures data security and prevents misuse. In POP, data is shared globally and can be modified by any function, which
reduces security.
2. A programmer writes a Java program that compiles successfully but produces incorrect output while calculating the average
marks of students. Identify the type of error and explain how it can be detected and corrected.
Ans. This is a logical error. Logical errors occur when the program runs successfully but produces incorrect results due to wrong logic.
The compiler cannot detect this type of error. It can be identified by testing the program with different inputs and checking
whether the output matches the expected result. The logic of the program must be reviewed and corrected.
E. Assertion and reasoning questions.
The following questions consist of two statements – Assertion (A) and Reason (R). Answer these questions by selecting the
appropriate option given below:
a. Both A and R are true and R is the correct explanation of A.
b. Both A and R are true but R is not the correct explanation of A.
c. A is true but R is false.
d. A is false but R is true.
1. Assertion (A): In object-oriented programming, data cannot be accessed directly by external functions.
Reason (R): OOP follows the concept of encapsulation, where data and methods are combined into a single unit called a class.
Ans. a. Both A and R are true and R is the correct explanation of A.
2. Assertion (A): Logical errors are detected by the compiler during compilation.
Reason (R): Logical errors occur when the program runs but produces incorrect output due to wrong logic.
Ans. d. A is false but R is true.
3. Assertion (A): Java applets execute on the client side within a web browser.
Reason (R): Java applets are small Java programs that are implanted in an HTML page and execute only within a web browser.
Ans. a. Both A and R are true and R is the correct explanation of A.
F. Case study-based questions.
Riya is learning about different types of programming languages in her computer science class. She writes a program using functions
to calculate the area and perimeter of a rectangle. In her program, data is shared between functions using global variables. She
designs the program using a top-down approach where the main function calls other smaller functions.
106 Touchpad Computer Science (Ver. 3.0)-XI

