Professional Documents
Culture Documents
ICSE9th
ICSE9th
ICSE9th
Chapter 1 - Unit 1
Principles of Object Oriented Programming
Write short notes:
Question 1: Object Oriented Programming
Answer: Object Oriented Programming is an approach in which stress is laid on data rather than
functions. The data values remain associated with the functions of a particular block of the program so as
to encourage data security.
Question 2: Data Abstraction
Answer : Data Abstraction is the act of representing the essential features without knowing the
background details
Question 3: Encapsulation
Answer : Wrapping of data and functions that operate on that data into a single unit is called
Encapsulation.
Question 4: Polymorphism
Answer : In object-oriented programming, Polymorphism provides the means to perform a single
action in multiple different ways. Example of Polymorphism is given here.
Question 5: Procedure Oriented Programming
Answer : Procedure Oriented Programming basically consists of a list of instructions for the
computer to follow and these are organized into groups known as functions. In Procedure Oriented
Programming, most of the functions share global data and this data moves more openly around the
system from one function to the other.
Question 6: Inheritance
Answer : Inheritance enables new classes to receive or inherit the properties and methods of
existing classes.
Distinguish between
Question 1: Object Oriented Programming and Procedure Oriented Programming
Object Oriented Programming Procedure Oriented Programming
The stress is put on data rather than functions. The stress is put on function rather than data.
The data is restricted, to be used in a specific program area. It allows data to flow freely throughout the program.
High Level language is machine independent. Low Level language is machine dependent.
High Level language is human friendly so it is easy to Low Level language is machine friendly so it is difficult
understand for programmers. to understand for programmers.
High Level language needs a compiler or interpreter for Low Level language might need a assembler for
translation to machine code. translation to machine code.
Programs written in High Level language are easier to Programs written in Low Level language are hard to
modify and debug. modify and debug.
Answer the following questions
Question 1: Enlist the features of Object Oriented Programming.
Answer : Some of the features of Object Oriented Programming are:
It gives stress on data items rather than functions.
It makes the complete program/problem simpler by dividing it into number of objects.
The objects can be used as a bridge to have data flow from one function to another.
The concept of data hiding enhances security in programs.
It is highly beneficial to solve complex programs.
Chapter 1 - Unit 2
Introduction to Java
Question 1: Mention at least four features of Java.
Answer : Four features of Java are:
It is an Object Oriented Programming Language.
It is platform independent. It provides us Write Once, Run Anywhere (WORA)
feature.
It uses a compiler as well as an interpreter.
It is case sensitive.
It translates the whole source program into target It translates the source program into target program
program at once. one line at a time.
All the errors found during compilation are Errors are displayed line by line as each line is
displayed together at once. translated and executed.
Question:You want to display your bio-data on the output screen. Write a program in Java to perform
the task in the given format:
Name:
Father's Name:
Date of birth:
Blood Group:
Aadhar Card No.:
State:
Answer
class BioData {
public static void main(String args[]) {
System.out.println("Name: Rahul Khanna");
System.out.println("Father's Name: Arvind Khanna");
System.out.println("Date of birth: 12/12/2005");
System.out.println("Blood Group: O+");
System.out.println("Aadhar Card No.: 4321 8756 9978" );
System.out.println("State: Maharashtra");
}
}
Question 2
Mention five states (characteristics) and two methods for the following Classes:
(a) Class Employee
Answer
Characteristics Methods
Name computeSalary()
Pan Number
Salary
Income Tax
(b) Class Bank
Answer
Characteristics Methods
IFSC Code
MICR Code
Accounts
(c) Class School
Answer
Characteristics Methods
Classes
Students
Teachers
(d) Class Book
Answer
Characteristics Methods
Price
Author
Publisher
Chapter 2
Elementary Concept of Object and Classes
Question 1:How will you define a software object?
Answer: A software object replaces the characteristics and behaviours of a real world object
with data members and member methods, respectively.
Question 2: Class and Objects are inter-related. Explain.
Answer: A Class is used to create various Objects that have different characteristics and
common behaviours. Each object follows all the features defined within a class. That is why
class is also referred to as a blue print or prototype of an object. This way we can say that they
are inter-related.
Question 3: Why is an Object called an 'Instance' of a class? Explain.
Answer: A class can create objects of itself with different characteristics and common
behaviour. So, we can say that an Object represents a specific state of the class. For these
reasons, an Object is called an Instance of a Class.
Question 4: Why is a class known as composite data type?
Answer: A class can contain data members of various primitive and reference data types.
Hence, class is known as composite data type.
Chapter 3
Values and Data Types
Write short answers
Question 1: What do you mean by data type?
Data types are used to identify the type of data a memory location can hold and the associated operations of
handling it.
Question 2: Define variable with an example.
A variable represents a memory location through a symbolic name which holds a known or unknown value of a
particular data type. This name of the variable is used in the program to refer to the stored value.
Example:
int mathScore = 95;
Question 3: What do you mean by constant? Explain with an example.
The keyword final before a variable declaration makes it a constant. Its value can't be changed in the program.
Example:
final int DAYS_IN_A_WEEK = 7;
Integer Constants represent whole number values like Floating Constants represent fractional numbers like
2, -16, 18246, 24041973, etc. 3.14159, -14.08, 42.0, 675.238, etc.
Integer Constants are assigned to variables of data type Floating Constants are assigned to variables of data type
— byte, short, int, long, char — float, double
(b) Token and Identifier
Token Identifier
A token is the smallest element of a program that is Identifiers are used to name things like classes,
meaningful to the compiler. objects, variables, arrays, functions an so on.
Character Constants are written by enclosing a String Constants are written by enclosing a set of
character within a pair of single quotes. characters within a pair of double quotes.
Character literals can be assigned to variables of any Boolean literals can only be assigned to variables
numeric data type — byte, short, int, long, float, double, declared as boolean
Character Literal Boolean Literal
char
Binary operators work on two operands. Ternary operator work on three operands.
It evaluates to true only if both of its operands It evaluates to true if one or both of its operands are
are true. true.
Example: Example:
int a = 8, b = 13, c = 0; int a = 8, b = 13, c = 0;
Logical AND (&&) Logical OR(||)
Example: Example:
int a = 99; int a = 99;
int b = ++a; int b = a++;
After the execution of these two statements, After the execution of these two statements, a will have
both a and b will have the value of 100. the value of 100 and b will have the value of 99.
It is the assignment operator used for assigning a It is the equality operator used to check if a variable is equal to
value to a variable. another variable or literal.
E.g. int a = 10; assigns 10 to variable a. E.g. if (a == 10) checks if variable a is equal to 10 or not.
Question 11
Evaluate the following expressions, if the values of the variables are:
a = 2, b = 3, and c = 9
(a) a - (b++) * (--c); (b) a * (++b) % c;
Answer Answer
a - (b++) * (--c) a * (++b) % c
⇒2-3*8 ⇒ a * (++b) % c
⇒2-3*8 ⇒ 2 * (4) % 9
⇒ 2 - 24 ⇒8%9
⇒ -22 ⇒8
Question 12:
If a = 5, b = 9, calculate the value of:
a += a++ - ++b + a;
Answer
a += a++ - ++b + a
⇒ a = a + (a++ - ++b + a)
⇒ a = 5 + (5 - 10 + 6)
⇒a=5+1
⇒a=6
Question 13:
Give the output of the program snippet.
int a = 10, b =12;
if(a>=10)
a++;
else
++b;
System.out.println(" a = " + a + " and b = " +b);
Output
a = 11 and b = 12
Explanation
The condition if(a>=10) is true so a++ increments a to 11. b remains the same.
Question 14
Rewrite the following using ternary operator.
if(income<=100000)
tax = 0;
else
tax = (0.1*income);
Answer
tax = income <= 100000 ? 0 : (0.1*income);
Question 15: Rewrite the following using ternary operator.
if(p>5000)
d = p*5/100;
else
d = 2*p/100;
Answer
d = p > 5000 ? p * 5 / 100 : 2 * p / 100;
Chapter 5
Input In Java
Name the following
Question 1: A package needed to import scanner class
java.util
Question 2: A method that accepts a character through scanner object
charAt()
Question 3: A method to accept an exponential value through scanner object
nextDouble()
Question 5: A method that accepts an integer token through scanner object
nextInt()
Scans the next token of input as an int Scans the next token of input as a float
Question 2
Syntax and logical errors
Syntax Errors Logical Errors
Syntax Errors occur when we violate the rules of writing the Logical Errors occur due to our mistakes in
statements of the programming language. programming logic.
Question 5:
Write down the syntax to input a character through scanner class with an example.
Syntax:
char <variable name> = <Scanner Object>.next().charAt(0);
Example:
Scanner in = new Scanner(System.in);
char ch = in.next().charAt(0);
Question 2
Write a program by using class 'Employee' to accept Basic Pay of an employee. Calculate the
allowances/deductions as given below.
Allowance / Deduction Rate
Question 3
A shopkeeper offers 10% discount on the printed price of a Digital Camera. However, a
customer has to pay 6% GST on the remaining amount. Write a program in Java to calculate
the amount to be paid by the customer taking printed price as an input.
import java.util.Scanner;
Question 5
Mr. Agarwal invests certain sum at 5% per annum compound interest for three years. Write a
program in Java to calculate:
(a) the interest for the first year
(b) the interest for the second year
(c) the amount after three years.
Take sum as an input from the user.
Sample Input: Principal = ₹5000, Rate =10%, Time = 3 yrs
Sample Output: Interest for the first year: ₹500
Interest for the second year: ₹550
Interest for the third year: ₹605
import java.util.Scanner;
Question 6
A businessman wishes to accumulate 3000 shares of a company. However, he already has
some shares of that company valuing ₹10 (nominal value) which yield 10% dividend per
annum and receive ₹2000 as dividend at the end of the year. Write a program in Java to
calculate the number of shares he has and how many more shares to be purchased to make
his target.
Hint: No. of share = (Annual dividend * 100) / (Nominal value * div%)
public class Shares
{
public static void main(String args[]) {
int sharesHeld = (2000 * 100)/(10 * 10);
System.out.println("No. of shares held currently = "
+ sharesHeld);
int sharesRequired = 3000 - sharesHeld;
System.out.println("No. of shares to purchase = "
+ sharesRequired);
}
}
Question 7
Write a program to input the time in seconds. Display the time after converting them into
hours, minutes and seconds.
Sample Input: Time in seconds 5420
Sample Output: 1 Hour 30 Minutes 20 Seconds
import java.util.Scanner;
Question 10
A shopkeeper sells two calculators for the same price. He earns 20% profit on one and suffers
a loss of 20% on the other. Write a program to find his total cost price of the calculators by
taking selling price as input.
Hint: CP = (SP / (1 + (profit / 100))) (when profit)
CP = (SP / (1 - (loss / 100))) (when loss)
import java.util.Scanner;
Question 4
Write a program to accept a number and check whether the number is divisible by 3 as well as 5. Otherwise,
decide:
(a) Is the number divisible by 3 and not by 5?
(b) Is the number divisible by 5 and not by 3?
(c) Is the number neither divisible by 3 nor by 5?
The program displays the message accordingly.
import java.util.Scanner;
Question 10
A cloth showroom has announced festival discounts and the gifts on the purchase of items, based on the total cost as given below:
Total Cost Discount Gift
Up to ₹ 2,000 5% Calculator
}
}