Chapter 1
Principles of Object
Oriented Programming
A. Tick () the correct option.
1. A set of instructions given to a computer to do a particular task.
a. Program b. High level Language
c. Object d. None of these
Ans. a. Program
2. An object is represented by two attributes, out of which one is characteristics and the other one
is ___________.
a. Behaviour b. Situation
c. Abstraction d. Encapsulation
Ans. a. Behaviour
3. Name the programming technique that implements programs as an organized collection of
interactive objects.
a. Procedure Oriented Programming b. Modular Programming
c. Object Oriented Programming d. None of these
Ans. c. Object Oriented Programming
4. Name the programming technique that specifies a series of well-structured steps and procedures
within its programming context to compose a program.
a. Procedure Oriented Programming b. Modular Programming
c. Object Oriented Programming d. None of these
Ans a. Procedure Oriented Programming
5. Name the characteristics of Object Oriented Programming that hides the complexity and
provides a simple interface.
a. Encapsulation b. Polymorphism
c. Abstraction d. Inheritance
Ans. c. Abstraction
6. What is the behaviour aspect of an object represented by?
a. Member Functions b. Data Members
c. Both a and b d. None of these
Ans. a. Member Functions
Computer Applications – IX (ICSE Course) Answers 2
7. What is the ability of an object to take on many forms called?
a. Polymorphism b. Encapsulation
c. Abstraction d. Inheritance
Ans. a. Polymorphism
8. What is the term that is used to represent hierarchical relationship of generalization?
a. Polymorphism b. Encapsulation
c. Abstraction d. Inheritance
Ans. d. Inheritance
9. Name the art of implementing Encapsulation in Object Oriented Programming.
a. Polymorphism b. Encapsulation
c. Abstraction d. class
Ans. d. class
10. What is meant by state of an object?
a. Functions of the object b. Data Members of the object
c. Content of an object d. All of these
Ans. c. Content of an object
B. State whether the following statements are True (T) or False (F).
1. Encapsulation refers to the art of hiding the complexities and giving a simple interface. F
2. Procedure Oriented Language follows top down approach. T
3. Java is an example of Object Oriented Language. T
4. Hiding the complexity and giving a simple interface is called Inheritance. F
5. Abstraction is same as Encapsulation. F
C. Fill in the blanks.
1. An object is an identity with certain characteristic and behaviour.
2. The values/attributes of the characteristics of an object are called the state of an object.
3. All the complexities of a program should be encapsulated in such a way so that Abstraction is
obtained.
4. Inheritance allows us to encompass the parent class’ state and behaviours into its child.
5. Poly-means many and Morphism means forms.
6. Encapsulation is a principle of Object Oriented Programming (OOP) that binds together
characteristics and behaviour of an object.
7. Abstraction is the reduction of a particular body of data to a simplified representation of
the whole.
3 Computer Applications – IX (ICSE Course) Answers
8. The characteristics of an object are represented through data members and behaviour is
represented through member functions.
9. A program written in a high level language is also called Source Code.
10. All objects have identity and are distinguishable even if the constituent components are same.
SECTION A
Answer the following questions.
1. Give two examples of real world objects. Also specify their characteristics and behaviour.
Ans. The book that you are reading now is also an example of an object. Its characteristics is
represented by the information it holds, size, volume and its colour. The behavioural aspect is
referred by the methods for accessing the information it contains.
A pen is also an example of object. Its characteristics is represented by its colour, shape, brand,
etc., and its behaviour is represented by its use such as writing, drawing, etc.
2. What do you understand by state of an object? Explain with an example.
Ans. The state of an object is the particular condition it is in. For example, a lamp can be on or off.
The lamp’s switch (methods) turn lamp on and turn lamp off are used to access the state of the
lamp.
3. How are objects implemented in Software?
Ans. In a software the characteristics of an object are represented through data members and
behaviour is represented through member functions.
4. What is abstraction? How is encapsulation related to it?
Ans. Abstraction is a principle of Object Oriented Programming (OOP) that hide certain details and
only show the essential features of the object.
Encapsulation is also frequently confused with abstraction, since the two concepts are closely
related. Abstraction is a process of hiding the complexity and giving a simple interface.
Encapsulation on the other hand is the mechanism by which the abstraction is implemented.
5. Define Encapsulation.
Ans. Encapsulation is a principle of Object Oriented Programming (OOP) that binds together
characteristics and behaviour of an object into a single unit represented by a class.
6. Explain the term object using an example.
Ans. The book that you are reading now is also an example of an object. Its characteristics is represented
by the information it holds, size, volume and its colour. The behavioral aspect is referred by the
methods for accessing the information it contains. For example, you can open the book, turn a
page, read a paragraph, and search the table of contents, and so on. The information contained
Computer Applications – IX (ICSE Course) Answers 4
in the book along with the methods for accessing it for gaining information is what comprises
the object known as this book.
7. What is Object Oriented Programming?
Ans. Object Oriented Programming (or OOP) is a technique of implementing programs which are
organized as a co-interactive collection of objects, each of which represents an instance of a
class.
8. State three differences between Procedure Oriented Language and Object Oriented Languages.
Ans.
Procedure Oriented Programming Object Oriented Programming
A large program is divided into smaller A program is represented as an object.
segments or procedures.
More importance is given to the program More importance is given to the data rather
rather than the data. than the program.
It follows top down approach. It follows bottom up approach.
9. State the four characteristics/principles of Object Oriented Programming.
Ans. Encapsulation, Abstraction, Polymorphism and Inheritance.
10. Give a real life example of Polymorphism.
Ans. Example in real life of polymorphism- Shobha is a married girl and mother of 2 children doing
teaching job then she is a women first, teacher in a school when she is at school, wife of someone
at home, mother of her children and obvious daughter of someone. Thus you can see that
Shobha plays different roles at different times that is what polymorphism is.
5 Computer Applications – IX (ICSE Course) Answers
Chapter 2
Introduction to Java
A. Tick () the correct option.
1. What was Java initially called?
a Oak b. C
c. C++ d. None of these
Ans. a. Oak
2. What is Java Programming Language?
a. A runtime system b. A set of development tools.
c. An Application Programming Interface (API) d. All of these
Ans. d. All of these
3. Name the process that converts source code to bytecode.
a. Interpretation b. Compilation
c. All of these d. None of these
Ans. b. Compilation
4. A Virtual Processor that is implemented in software and runs using the capabilities provided by
your operating system and computer hardware.
a. Byte Code b. Compiler
c. Interpreter d. Java Virtual Machine(JVM)
Ans. d. Java Virtual Machine(JVM)
5. Which among the following is not a language feature in Java?
a. Robust b. Secured
c. Platform Independent d. Procedure Oriented
Ans. d. Procedure Oriented
6. Name the programs that can be developed in such a way that it remains embedded in a web
page and runs on the viewer’s machine in a secured manner by Java compatible browsers.
a. Applets b. Applications
c. Both a and b d. None of these
Ans. a. Applets
Computer Applications – IX (ICSE Course) Answers 6
7. Name the Application program that is written and compiled which may then be executed in any
machine provided it contains the JVM.
a. Applets b. Applications
c. Both a and b d. None of these
Ans. b. Applications
8. What is the extension of a source code in Java?
a. .java b. .class
c. Both a and b d. None of these
Ans. a. .java
9. What is the extension of the byte code in Java?
a. .java b. .class
c. Both a and b d. None of these
Ans. b. .class
10. What is a set of pseudo machine language instructions that are understood by the Java Virtual
Machine and are independent of the underlying hardware called?
a. JVM b. Source Code
c. Compilation d. Bytecode
Ans. d. Bytecode
B. Fill in the blanks.
1. James Arthur Gosling is called the father of Java programming language.
2. Java was formerly known as Oak.
3. A Java program written in a text editor is called the Source code.
4. Bytecode is a set of pseudo machine language instructions that are understood by the JVM.
5. Java is independent of the underlying hardware and software and is therefore called platform
independent.
6. The process of converting a source code to byte code is called compilation.
7. A platform is the hardware/software environment in which a program remains.
8. The byte code file in Java has the .class extension.
9. JVM is a microprocessor that is implemented in software and runs using the capabilities provided
by your operating system and computer hardware.
10. Multi-threading is a process of executing multiple threads simultaneously.
7 Computer Applications – IX (ICSE Course) Answers
C. State whether the following statements are True (T) or False (F).
1. The byte code when compiled gives source code. F
2. A Java program can execute only in Windows machine. F
3. A Java API is a collection of prewritten packages, classes, and interfaces with
their respective methods, fields and constructors. T
4. Source Code in Java has the .class extension. F
5. Java is simple to learn. T
SECTION A
Short answer type questions.
1. Name two types of Java programs.
Ans. Application and Applet
2. What is Java API?
Ans. An application programming interface (API), in the context of Java, is a collection of prewritten
packages, classes, and interfaces with their respective methods, fields and constructors.
3. Define the term Byte Code.
Ans. Java bytecode is the result of the compilation of a Java program, an intermediate representation
of that program which is machine independent. The Java bytecode gets processed by the Java
virtual machine (JVM) instead of the processor.
4. What is JVM? Explain its relationship with byte code.
Ans. The Java Virtual Machine (JVM) is the runtime engine of the Java Platform, which allows any
program written in Java or other language compiled into Java bytecode to run on any computer
that has a native JVM.
5. What is a platform? How does it differ from a Java platform?
Ans. A platform is the hardware or software environment in which a program remains. The Java
platform differs from most other platforms in that it’s a software only platform that runs on top
of other hardware-based platforms.
6. State the difference between Applet and Application.
Ans. The fundamental difference between the two Java programs is that an application program is
designed to run on a stand-alone machine whereas an applet is a web-version of an application
which is used to run a program on a web browser.
7. What makes Java suitable to create secured applications?
Ans. Java is designed to be secure in a networked environment. It is designed with multiple layers
of security countermeasures embedded in the compiler, runtime system, and in browsers that
support Java. These countermeasures make Java inherently more secure for developing any type
of trusted application software. The Java run-time environment uses a byte code verification
process to ensure that code loaded over the network does not violate Java security constraints.
Computer Applications – IX (ICSE Course) Answers 8
8. What does the Robust feature in Java mean?
Ans. The term robust means strong or vigorous. Java uses some strong design measures to eliminate
certain types of programming errors. It allows extensive compile-time error checking. Therefore
most of the errors will be trapped and need to be rectified during compilation.
9. State four features of Java.
Ans. Simple, Robust, Secured and Platform Independent.
10. What is Multithreading in Java?
Ans. Multithreading is a process of executing multiple threads simultaneously. Thread is basically a
lightweight sub-process, a smallest unit of processing. The main purpose of multithreading in
Java is to provide simultaneous execution of two or more parts of a program to utilize the CPU
to the maximum.
11. What makes Java Architecture Neutral?
Ans. In Java there are no implementation dependent features. In most of other languages you need
to know features that are hardware or OS dependent. For example in a high-level language
called C the int data type occupies 2 bytes of memory for 32-bit architecture and 4 bytes of
memory for 64-bit architecture. But in java, it occupies 4 bytes of memory for both 32 and 64
bit architectures.
12. What is WORA?
Ans. “Write once, run anywhere” (WORA), or sometimes write once, run everywhere (WORE),
is a slogan created by Sun Microsystems to illustrate the cross-platform benefits of the Java
language.
13. Explain the statement “Byte code is the object code for the JVM”.
Ans. Normally object code refers to a program in a form that the host system can run directly. As java
source code is converted to bytecode during compilation which is then recognised by the JVM,
Thus bytecode is sometimes referred to as the object code for the JVM.
9 Computer Applications – IX (ICSE Course) Answers
Chapter 3
Elementary Concept of
Objects and Classes
A. Tick () the correct option.
1. Which among the following creates a blueprint to represent characteristic and behaviour of
an object?
a. Object b. Class
c. Instance d. None of these
Ans. b. Class
2. Which among the following do not belong to an object?
a. State b. Behaviour
c. Identity d. Class
Ans. a. State
3. Which among the following is not a component of a class?
a. Modifiers b. Class name
c. Object d. Body
Ans. c. Object
4. Which among the following keyword is used to allocate memory space for an object?
a. new b. for
c. while d. int
Ans. a. new
5. Which among the following operator is used to access individual members of an object?
a. . (dot) b. + (plus)
c. – (minus) d. / (divide)
Ans. a. .(dot)
6. Which among the following modifier is used in a ‘class’?
a. public b. default
c. Both a and b d. None of these
Ans. c. Both a and b
Computer Applications – IX (ICSE Course) Answers 10
7. Which among the following is a valid class name?
a. Simple Interest b. SimpleInterest
c. 1SimpleInterest d. Simple@Interest
Ans. b. SimpleInterest
8. Which among the following is a valid object name?
a. obj1 b. 1obj
c. Obj 1 d. Obj#1
Ans. a. obj1
9. Which among the following is used to represent behaviour in a class?
a. Method b. Data members
c. Both a and b d. None of these
Ans. a. Method
10. If a method named show( ) is to be invoked using an object ‘ob’ , which among the following is
correct?
a. ob.show( ) b. ob.show
c. show( ).ob d. None of these
Ans. a. ob.show()
B. State whether the following statements are True (T) or False (F).
1. An object is called a class factory. F
2. A class is an instance of an object. F
3. A class is a mechanism to implement encapsulation. T
4. Data members in a class is used to represent the characteristic of an object. T
5. The new operator is used to create an object. T
6. It’s a rule to have a class-name beginning in capital letter. F
7. Java is case sensitive. T
8. A class-name cannot be a keyword. T
9. The dot operator is used to access members in an object using an object. T
10. In programming every object will have a name. T
C. Fill in the blanks.
1. A class is a template that binds together data and methods together.
2. The values in the attributes of an object is called the state of an object.
3. The . dot operator is used to access the individual members of a class.
11 Computer Applications – IX (ICSE Course) Answers
4. The keyword new is used to allocate memory space for an object.
5. The default and public access modifier is used with a class.
6. It is a common convention to begin a class-name in capital letter.
7. A class is called an object factory.
8. Object-name is used to give a unique name to an object for identification.
9. Behaviour of an object is represented by methods.
10. The size of fundamental data type is fixed.
SECTION A
Answer the following questions.
1. State two differences between fundamental and user-defined data type.
Ans.
Comparison of Fundamental & User defined data type.
Fundamental data type User defined data type
These are inbuilt data type provided by These are data types created by the user
the Java Language. using fundamental or user defined data
type or both.
The size of it is fixed. The size of different user-defined data
type depends upon the size of the
individual components of it.
These data types are available in all parts These data types are available only as
of a program within a class. specified by the access specifiers.
2. State two differences between a class and an object.
Ans.
A class An object
Class is a blueprint or template from Object is an instance of a class.
which objects are created.
Class is a group of similar objects. Object is a real world entity such as pen,
laptop, mobile, bed, keyboard, mouse, chair
etc.
Class is a logical entity. Object is a physical entity.
3. Why is a class called a user-defined data type?
Ans. Primitive data types are the general and fundamental data types that we have in Java and those
are byte, short, int, long, float, double, char, boolean, etc., User defined data types are those
that user / programmer himself defines.
Computer Applications – IX (ICSE Course) Answers 12
4. What is an access specifier? Which two access specifier is used in a class declaration?
Ans. Access modifiers (or access specifiers) are keywords in object-oriented languages that set the
accessibility of classes, methods, and other members. Access modifiers are a specific part of
programming language syntax used to facilitate the encapsulation of components.
The public and default access specifier is used in a class declaration.
5. Why is a class called an object factory?
Ans. A class is called an object factory because objects are created from a class. An object is an
instance of a class.
The following statements create two objects s1 and s2 of the class Student.
Student s1 = new Student();
Student s2 = new Student();
So, we have a single class Student but we can create as many objects as we want (like s1, s2, etc.)
from that single class.
This is similar to what happens in a factory. Consider a factory which produces car. They have
only a single design of a car but produce multiple cars from that single design.
Things are similar in the world of classes and objects. There is a single definition of a particular
class (like Student) but we can produce many Student objects (like s1, s2) from that single class.
6. State two rules you should follow for naming a class.
Ans. While using names for a class the following set of rules are to be kept in mind.
1. It can have any alphabet (capital or small), digits, underscore and dollar sign characters. For
example, a, b, cat, mat123, cost_price, Topaz$ are all example of valid identifier.
2. It should not begin with digits or should not contain any special character. For example 2ab,
ab#c, top@, etc., are invalid identifiers as it either begins with a digit or contain special
characters (like #, @).
3. It cannot have a space between it. For example, Simple Interest or Selling Price are invalid
class-names as it contains a space.
4. It must not be a keyword. For example, for, while, do are invalid class-names as they are
keywords and are assigned some special function for the language.
5. It can be of any length. Even though Java gives you the flexibility to provide a huge length for
an identifier a very long name is impractical and difficult to manage.
7. What two conventions you should follow naming a class?
Ans. Conventions for class name:
1. Class name should begin with capital letter. Example, Bank, School, Student
2. If a class name consists of more than one word, the first letter of each new word should be
in uppercase. For example MyClass, AccountDetails, SimpleInterest, etc.
13 Computer Applications – IX (ICSE Course) Answers
8. State two conventions you should follow while naming a class.
Ans. Class name should begin with capital letter. Example, Bank, School, Student
If a class name consists of more than one word, the first letter of each new word should be in
uppercase. For example MyClass, AccountDetails, SimpleInterest, etc.
9. Write a statement in Java that will declare an object named si of the SimpleInterest class.
Ans. SimpleInterest si=new SimpleInterest( );
10. Rewrite the following program after removing the errors, underlining each corrections:
class My Class
{
int a, b;
void initialize( )
{
a=5;
b=6;
}
void show( )
{
System.out.println(a+ “ ”+ b);
}
static void main( )
{
My Class ob = new My Class( );
ob.initialize( );
show( ).ob;
}
}
Ans.
class MyClass
{
int a, b;
void initialize( )
Computer Applications – IX (ICSE Course) Answers 14
{
a=5;
b=6;
}
void show( )
{
System.out.println(a+ “ ” + b);
}
static void main( )
{
MyClass ob = new MyClass( );
ob.initialize( );
ob.show( );
}
}
11. Which among the following are invalid class name in Java? State with reasons.
1. Compound Interest
Ans. Invalid as it contains a space.
2. 1MyClass
Ans. Invalid as it should not begin with a digit.
3. MyClass$
Ans. Valid
4. Myclass#
Ans. Invalid as it contains a special character #.
5. My@Class
Ans. Invalid as it contains a special character @.
15 Computer Applications – IX (ICSE Course) Answers
Chapter 4
Values and Data Types
A. Tick (√) the correct option.
1. Which among the following encoding system can represent 65536 characters?
a. ASCII b. Unicode
c. Both a and b d. None of these
Ans. b. Unicode
2. Which among the following is not a Token?
a. Keywords b. Literals
c. Identifiers d. Data Type
Ans. d. Data Type
3. Which among the following is a keyword but not a literal?
a. for b. null
c. true d. false
Ans. a. for
4. Which among the following is a valid float literal?
a. 12.36f b. 12.36F
c. 12.36 d. Both a and b
Ans. d. Both a and b
5. Which among the following is a valid octal integer literal?
a. 0178 b. 675
c. 0675 d. 0X675
Ans. c. 0675
6. Which among the following is a valid method of initialising?
a. boolean f=true; b. boolean f=True;
c. boolean f=’true’; d. None of these
Ans. a. boolean f= true;
7. Which among the following is not a punctuator?
a. ; semicolon b. , comma
c. : colon d. . dot
Ans. c. : colon
Computer Applications – IX (ICSE Course) Answers 16
8. Which among the following is not a primitive data type?
a. int b. float
c. String d. char
Ans. c. String
9. What is the largest possible value that can be stored in short data type?
a. 215-1 b. 231-1
c. 27-1 d. 263-1
Ans. a. 215-1
10. If a is of type int and b is of type float what would be the resultant data type of a+b?
a. int b. float
c. double d. short
Ans. b. float
B. Fill in the blanks.
1. Character Set is a valid set of characters used in a Java language.
2. A unicode is a type encoding that can represent characters of all the languages of the world.
3. Token is the fundamental building block of a program.
4. Keywords are reserved words in Java that provide a special meaning to the java compiler.
5. The names given to different parts of a program are called Identifiers.
6. Octal integer literals are always prefixed with 0.
7. Literals that are enclosed within double quotes are called String literals.
8. Symbolic constant declarations are always preceded with the final keyword.
9. Operators are special symbols that perform specific operations on one or more operands and
then return a result.
10. The true and false literals are both boolean literals.
SECTION A
A. Very short answer type questions
1. Identify the mistake in each of these lines and correct it:
a. int goto=5;
Ans. The identifier goto is invalid, as it is an identifier.
Correction: int g=5;
b. float a=12.3;
Ans. The float literals should be suffixed with ‘f’.
Correction: float a=12.3f;
17 Computer Applications – IX (ICSE Course) Answers
c. doubles b=15;
Ans. The data type is wrongly spelled.
Correction: double b=15;
d. long b=1536458888397632;
Ans. The long literal should be suffixed with an ‘L’.
Correction: long b=1536458888397632L;
e. String s= ‘Computer’;
Ans. String literals should be enclosed in double quotes.
Correction: String s= “Computer”;
2. State with reasons why are the following variable names invalid:
a. for
Ans. Invalid, as for is a keyword.
b. book list
Ans. Invalid, as a space cannot be present in a variable name.
c. 2ndTerm
Ans. Invalid, as a variable name cannot begin with a digit.
d. hash#
Ans. Invalid, as a variable name cannot have a special character like #.
e. sick@always
Ans. Invalid, as a variable name cannot have a special character like @.
3. What is the resultant data type of the following mathematical expression?
a+b*c-d
a. where a is int, b is int, c is float and d is float type
Ans. float
b. where a is float, b is long, c and d are of int type
Ans. float
c. where a is of double and b,c and d are of int type.
Ans. double
d. where a is char and b,c and d are of int type
Ans. int.
e. where a, b, c and d are of int type, however the expression is slightly modified as (a+b*c-d)/7.0
Ans. double
Computer Applications – IX (ICSE Course) Answers 18
B. Short answer type questions
State with reasons why are the following initializations incorrect:
a. int a=5;
short b=a;
Ans. The short b=a; is invalid as an int cannot be initialised to a short type variable.
b. double a=5.3;
float b=a;
Ans. The float b=a; is invalid as a which is of double type cannot be initialised to a variable of float
type.
c. int a=01238;
Ans. The int a =01238; is invalid as an starting with a 0 is considered to be of octal data type and
therefore cannot have a digit 8.
d. float a=17.36f;
int b=a;
Ans. The int b=a; is invalid as a is of float type, that cannot be initialised to a variable b of int type.
e. boolean a=true;
int b=a;
Ans. The int b=a; is invalid as the assignment is of incompatible type.
C. Answer the following questions.
1. What is Character Set?
Ans. A character set is a set of alphabets, letters and some special characters that are valid in Java
language.
2. What are keywords?
Ans. A keyword is a reserved word that have a special significance to the compiler and cannot be
used anywhere else other than what it is intended for.
3. What are Identifiers? State the rules while using Identifiers.
Ans. Identifiers are the names of variables, methods, classes, packages and interfaces.
While using identifiers the following set of rules are to be kept in mind.
1. It can have any alphabet (capital or small), digits, underscore and dollar sign characters. For
example, a, b, cat, mat123, cost_price, Topaz$ are all example of valid identifier.
2. It should not begin with digits or should not contain any special character. For example
2ab, ab#c, top@, etc, are invalid identifiers as it either begins with a digit or contain special
characters (like #, @).
3. It cannot have a space between it. For example, simple interest or selling price are invalid
identifiers as it contains a space.
19 Computer Applications – IX (ICSE Course) Answers
4. It must not be a keyword. For example, for, while, do are invalid identifiers as they are
keywords and are assigned some special function for the language.
5. It can be of any length. Even though Java gives you the flexibility to provide a huge length for
an identifier a very long name is impractical and difficult to manage.
4. What is a literal? What are the different types of literals available in Java?
Ans. Literal is a constant value that can be assigned to a variable.
The different types of literals in Java are:
1. Integer-literal or Fixed point-literal
2. Floating point-literal
3. Boolean-literal
4. Character-literal
5. String-literal
6. Null-literal
7. Class literal
5. State the difference between a boolean literal and a character literal.
Ans. A boolean literal may be either true or false and character literal are always enclosed within
single quotes.
6. How are Decimal, Octal and Hexadecimal integer literals represented in Java?
Ans. Decimal Integer Literals uses digits from 0 to 9 (i.e. 10 digits this is what you normally use to
represent numbers in mathematics) but should not be prefixed with 0. + (or no symbol) or – may
be used to represent positive or negative numbers respectively. Thus -12, 56, or +75 may be
considered to be Decimal Integer Literal.
Octal Integer Literals uses digits from 0 to 7 (i.e. 8 digits) and should be prefixed with 0. + (or
no symbol) or – may be used to represent positive or negative numbers respectively. Thus -012,
056, or +075 may be considered to be Octal Integer Literal.
Hexadecimal Integer Literals uses digits from 0 to 9 and alphabets from A (or a) to F (or f)
representing 10 to 15 (i.e. 16 numbers) and should be prefixed with 0x or 0X. + (or no symbol)
used to represent positive numbers or – may be used to represent negative numbers. Thus
-0x12, 0X56, or +0A7F5 may be considered to be Hexadecimal Integer Literal.
7. Write any two escape sequences used in Java.
Ans. For newline :\n
For tab: \t
8. What are the different punctuators available in Java?
Ans. There are 9 punctuators available in Java. They are:
(){}[];,.
9. What are Tokens?
Ans. Token is the fundamental building block of a program that represents a single element of a
programming language.
Computer Applications – IX (ICSE Course) Answers 20
10. State the difference between token and identifier.
Ans. Token is the fundamental building block of a program that represents a single element of a
programming language. Identifier on the other hand is a token that is used to name different
parts of a program.
11. State the two kinds of data types.
Ans. Primitive data type and Composite data type.
12. What is the smallest and the largest number that can be stored into a variable of int data
type?
Ans. Smallest: - 231
Largest = 2 31- 1
13. How are floating point numbers represented in Java?
Ans. It should be suffixed with f or F.
14. What are variables? How are variables initialized?
Ans. Variables are names given to memory location. Variables are initialised during declaration. For
example,
int a=25;
15. How are symbolic constants represented in Java?
Ans. Symbolic constants are prefixed with the final keyword during declaration. For example,
final int a =100;
16. What are separators?
Ans. Separators are special symbols used to separate statements, data elements or mark blocks in
Java and is therefore also called separators. There are 9 punctuators available in Java. They are:
(){}[];,.
17. What is Type Conversion? Name the two type conversions in Java.
Ans. In a mathematical expression containing operands of more than one data type necessitates to
know the resultant data type of an expression. The resultant data type of an expression can be
categorized into two segments.
• Implicit type conversion
• Explicit type conversion
18. Name two keywords which are also literals in Java.
Ans. They are null, true and false.
19. What do you understand by variable scope?
Ans. Variable scope is the area in which a variable is accessible or have its life.
20. What are the three types of integer literals that can be represented in Java?
Ans. Decimal Integer Literal, Octal Integer Literal and Hexadecimal Integer Literal.
21 Computer Applications – IX (ICSE Course) Answers
Chapter 5
Operators in Java
Tick (√) the correct option.
1. Which among the following is a relational operator?
a. + b. > c. * d. /
Ans. a. +
2. The && operator requires which among the following conditions to be satisfied to represent a
success for two relations?
a. Both should be satisfied b. Any one should be satisfied.
c. None of them are satisfied. d. None of these
Ans. a. Both should be satisfied
3. Which among the following is not a logical operator?
a. && b. || c. ! d. <=
Ans. d. <=
4. Which among the following operators is used to dynamically allocate memory space for an
object?
a. . (dot) b. > c. == d. new
Ans. d. new
5. Which among the following is the correct construct for creating an object named ‘book’ of the
‘Library’ class?
a. Library book=new Library; b. book =new Library();
c. Library() book=new Library(); d. Library book=new Library();
Ans. d. Library book=new Library();
6. Which operator is used to access individual members of an object?
a. . (dot) b. > c. == d. New
Ans. a. . (dot)
7. The member ‘out’ object of the ‘System’ class belongs to which class?
a. System b. Print c. PrintStream d. Println
Ans. a. System
Computer Applications – IX (ICSE Course) Answers 22
8. The statement a%2 will result to what if the value of a is an even number?
a. 0 b. 1 c. Both a and b d. None of these
Ans. a. 0
9. Which among the following operators is used to check the two operands are equal or not?
a. Equals b. = c. == d. None of these
Ans. c. ==
10. Which among the following forms of operators works with three operands?
a. Unary b. Binary c. Ternary d. None of these
Ans. c. Ternary
SECTION A
Answer the following questions
1. What is an operator? How is the classification of operators based upon?
Ans. An operator is a specialised symbol that performs a specific kind of evaluation on one, two, or
three operands, and produces a result.
Operators in Java can be categorized based on two criteria:
• Forms of operators
• Types of operators
2. What are the different forms of operators?
Ans. Forms of operators groups operators in terms of the number of operands. There are three types
of operators based on the number of operands. An operator is called a unary, binary, or ternary
operator based on the number of operands. If an operator takes one operand, it called a unary
operator; if it takes two operands, it called a binary operator; if it takes three operands, it called
a ternary operator.
3. What is assignment operator? Explain with the help of an example.
Ans. The Assignment operator is used to assign or give a value to a variable.
int a, b, c; Declare 3 variables
b = 25; a, b and c of int
c = b; data type.
Left hand
Right hand
operand.
operand.
23 Computer Applications – IX (ICSE Course) Answers
4. What are Arithmetic operators? What are the different forms of arithmetic operators?
Ans. Arithmetic operators are used to evaluate mathematical expressions.
Arithmetic operators are a form of operator that may either by a Unary Operator or a Binary
Operator.
5. What is increment/decrement operator used for? Explain with the help of an example.
Ans The increment/decrement operator is used to increase/decrease the value of a variable by 1.
For example a++; increases the value of the variable a by 1, similarly a--; decreases the value of
the variable a by 1.
6. What is an expression?
Ans. An expression is a construct that is made up of variables, operators and method invocations,
which are constructed according to the syntax of the language that evaluates to a single value.
7. State the different types of binary arithmetic operators. Also state their hierarchy of operations.
Ans These are operators that work on two operands. The operator is placed between the operands.
The symbols that are used as binary arithmetic operators are:
+ For performing addition
- For performing subtraction.
* For performing multiplication.
/ For performing division.
% For getting the remainder when divided.
Hierarchy of Arithmetic Operators
1. First Brackets/Parenthesis: In Java the expression in bracket is done first. However brackets
in an expression should only be first bracket ( ). Nested brackets can also be used, but in that
case the expressions in the innermost bracket are done first and then the subsequent outer-
level brackets. Eg. (5+6*(7-3)) will give 29. Notice that only first-bracket is used.
2. Then /, *, or % whichever comes first while evaluating from left to right will get evaluated
first.
3. Then + or – whichever comes first while evaluating from left to right will get evaluated first..
8. What is Operator Associativity? What is the operator associativity of prefix/postfix increment/
decrement operators?
Ans. Operator Associativity is a property that determines how operators of the same precedence are
grouped in the absence of parentheses; i.e., in what order each operator is evaluated.
Operator Description Associativity
++ Post-Increment
left to right
−− Post-Increment
++ Pre-Increment
right to left
−− Pre-Increment
Computer Applications – IX (ICSE Course) Answers 24
9. What are short hand operators? Explain with an example.
Ans. Java provides special operators that can be used to combine an arithmetic operation with an
assignment. For example, the expression,
a = a+4;
can be written as,
a += 4;
As this operator is a shorter way of expressing an expression it is also sometimes called Short
hand operators.
10. What is an accumulator?
Ans. An accumulator is a variable that the program uses to calculate a sum or product of a series of
values.
11. What are counters?
Ans. Counter is a variable that keeps track of the number of times an operation has been performed.
12. Name the relational operators along with their usage in Java.
Ans.
Relational operator Usage
> Greater than
< Less than
>= Greater than or equal to
<= Less than or equal to
== Equal to
!= Not equal to
13. Name the logical operators used in Java.
Ans.
Logical Operator Name Behaviour
&& AND operator Checks whether the conditions preceding and
succeeding it is true or not.
|| OR operator Checks whether either of the conditions
preceding and succeeding it is true or not.
! NOT operator Just negates the logic of the condition
succeeding it to check for its validity.
25 Computer Applications – IX (ICSE Course) Answers
14. Give the general syntax of conditional operator and also label its operands.
Ans. It has the following general syntax:
Test-condition? statement1 : statement2;
Operand 1 Operand 2 Operand 3
15. What is the use of:
a. Dot (.) operator
b. new operator
Ans. a. The dot operator is used to access or invoke individual members of a class.
b. The new operator dynamically allocates memory space for an object.
B. What will be the output of the following program?
1. class Output1
{
static void main()
{
int a=5,b=6,c;
c=a+b%2;
b=a+2*c;
System.out.println(c);
System.out.println(b);
}
}
Ans. 5
15
2. class Output2
{
static void main()
{
int a=12,b=13,c=6;
c+=a+b%2;
b-=a+2*c;
System.out.println(c);
System.out.println(b);
Computer Applications – IX (ICSE Course) Answers 26
}
}
Ans.
19
-37
3. class Output3
{
static void main()
{
int a=12,b=13,c=0,d=1;
c+=a;
c+=b;
d*=a;
d*=b;
System.out.println(c);
System.out.println(d);
}
}
Ans. 25
156
4. class Output4
{
static void main()
{
int a=12,b=13,c;
c=a++ + ++a/7 + b++;
System.out.println(a+“\t”+b+“\t”+c);
c=++a + a++/3 + ++b;
System.out.println(a+“\t”+b+“\t”+c);
}
}
Ans.
14 14 27
16 15 35
27 Computer Applications – IX (ICSE Course) Answers
5. class Output5
{
static void main()
{
int a=12,b=13;
boolean c;
c=a++ > b++;
System.out.println(a+“\t”+b+“\t”+c);
c=++a < --b;
System.out.println(a+“\t”+b+“\t”+c);
}
}
Ans.
13 14 false
14 13 false
C. Short Answer Type Questions.
1. Write the corresponding expressions for the following mathematical operations:-
i. c= a2 + b2
ii. z = x3 + y3 - xy /z
Ans. i. c= a*a + b*b
ii. z=x*x*x + y*y*y – x*y /z;
2. What will be the output for the following program segment?
int a = 0, b = 30, c = 40;
a = − −b + c++ + b;
System.out.println(“a =” + a);
Ans. a=98
3. if m = 5 and n = 2 output the values of m and n after execution in (i) and (ii):-
i. m − = n;
ii. n = m + m/n;
Ans. i. m=3 and n=2
ii. m=5 and n=7
Computer Applications – IX (ICSE Course) Answers 28
4. What will be the output of the following, if x = 5 initially?
i. 5 *++x
ii. 5*x++
Ans. i. 30
ii. 25
5. Evaluate the following expressions, if the values of the variables are a = 2, b=3 and c=9
i. a − (b++) * (− −c)
ii. a * (++b) % c
Ans. i. – 22
ii. 8
6. If a = 5, b = 9 calculate the value of:
a+ = a++ - ++b + a
Ans. a=6 and b=10
7. What is the result stored in x, after evaluating the following expression?
int x = 5;
x = x++ *2 + 3 * –x;
Ans. x=-8
8. State the value a, b and c after the execution of each of the following statements where a=12,
b=13 and c=11:
i. a=a++ + – –b + c++;
Ans. a=35,b= 12 and c= 12
ii. b=b++ + ++a * 2;
Ans. a=13, b= 39 and c=11
iii. c=c++ + a++ * (++b);
Ans. a=13, b= 14 and c=179
iv. b=b++ + ++b + c++ + ++a;
Ans. a=13, b= 52 and c= 12
v. b+= --c + ++c + a++ + (b++);
Ans. a=13, b= 59 and c=11
9. Write the following statements using correct usage of the operators:
i. X is greater than equal to Y.
Ans. X>=Y
ii. X is not equal to Y.
29 Computer Applications – IX (ICSE Course) Answers
Ans. X!=Y
iii. X is equal to Y.
Ans. X==Y
iv. X is less than Y and X is less than Z.
Ans. X<Y && X<Z
v. Either X is greater than Y or X is less than Z.
Ans. X>Y || X<Z
vi. If X has a value greater than 20 then increment the value of J by 1 otherwise decrement
the value by 2.
Ans. J=(X>20)?J+1:J-2;
SECTION B
Programming Questions
1. Write a program to find the sum and difference between 25 and 16 using variables in different
lines.
Ans. class Q1
{
static void main()
{
int a=25,b=16,s,d;
s=a+b;
d=a-b;
System.out.println(“Sum=”+s);
System.out.println(“Difference=”+d);
}
}
2. Write a program to find the product of 5, 7 and 12 using variables.
Ans. class Q2
{
static void main()
{
int a=5,b=7,c=12,d;
d=a*b*c;
System.out.println(“Product=”+d);
Computer Applications – IX (ICSE Course) Answers 30
}
}
3. Write a program to find the product of the sum and difference between 17 and 2 using
variables.
Ans. class Q3
{
static void main()
{
int a=17,b=2,s,d,p;
s=a+b;
d=a-b;
p=s*d;
System.out.println(“Product=”+p);
}
}
4. Write a program to average of 36,45 and 53 using variables of adequate data type.
Ans. class Q4
{
static void main()
{
int a=36,b=45,c=53;
float d;
d=(float)(a+b+c)/3;
System.out.println(“Average=”+d);
}
}
5. Write a program using int variables to find the sum of three numbers say 15, 36 and 45 and
subtract the result from 100 using variables.
Ans. class Q5
{
static void main()
{
int a=15,b=36,c=45,d;
d=100-(a+b+c);
31 Computer Applications – IX (ICSE Course) Answers
System.out.println(“Answer=”+d);
}
}
6. Write a program to display the names of five fruits with a single System.out.println();
statement, but in different lines.
Ans. class Q6
{
static void main()
{
System.out.println(“Apple\nMango\nGuava\nPomegranate\nJack fruit”);
}
}
7. Write a program to find the sum, difference and product of 12.35 and 7.3 using variables with
a single System.out.println(); statement, however with horizontal tab space in the result.
Ans. class Q7
{
static void main()
{
float a=12.35f,b=7.3f,s,d,p;
s=a+b;
d=a-b;
p=a*b;
System.out.println(s+“\t”+d+“\t”+p);
}
}
8. Write a program using float type variables to find the area and perimeter of a square whose
side is 12.5 cm.
Ans. class Q8
{
static void main()
{
float s=12.5f,a,p;
a=s*s;
p=4*s;
Computer Applications – IX (ICSE Course) Answers 32
System.out.println(“Area=”+a);
System.out.println(“Perimeter=”+p);
}
}
9. Write a program using int variables to find the area and perimeter of a rectangle of length
12cm and breadth 8cm.
Ans. class Q9
{
static void main()
{
int l=12,b=8,a,p;
a=l*b;
p=2*(l+b);
System.out.println(“Area=”+a);
System.out.println(“Perimeter=”+p);
}
}
10. Write a program using variables to find the profit and profit percent of a certain transaction
where S.P.=₹ 10000 and C.P.=₹ 7000.
Ans. class Q10
{
static void main()
{
float sp=10000,cp=7000,p,pp;
p=sp-cp;
pp=p/cp*100;
System.out.println(“Profit=”+p);
System.out.println(“Profit Percent=”+pp);
}
}
11. Write a program using variables to find the cost of 17 pencils if the cost of one pencil=₹ 2.50.
Output should be:
Cost of 1 pencil=₹2.5
Cost of 17 pencils=₹42.5
Ans. class Q11
{
static void main()
33 Computer Applications – IX (ICSE Course) Answers
{
float cp=2.50f,n=17,tc;
tc=cp*n;
System.out.println(“Cost of 1 pencil=Rs”+cp);
System.out.println(“Cost of 17 pencils=Rs”+tc);
}
}
12. Write a program using variables to find the area and circumference of a circle whose radius is
12cm.
Note that:
Area of a circle= π r2
Circumference of a circle = 2 π r
Where r is the radius of the circle and π is 3.142.
Ans. class Q12
{
static void main()
{
float r=12,pi=3.142f,a,c;
a=pi*r*r;
c=2*pi*r;
System.out.println(“Areas”+a);
System.out.println(“Circumference”+c);
}
}
13. Write a program to initialize two integer variables a and b with 5 and 6 respectively and
interchange them. Thus after interchanging, a and b will be 6 and 5 respectively.
Ans. class Q13
{
static void main()
{
int a=5,b=6,t;
t=a;
a=b;
b=t;
Computer Applications – IX (ICSE Course) Answers 34
System.out.println(a+“\t”+b);
}
}
14. Write a program to initialize three int variables a, b and c with 234, 456 and 712 and store the
sum of the last digits of the variables into d and display it.
Ans. class Q14
{
static void main()
{
int a=234,b=456,c=712,l1,l2,l3,d;
d=a%10+b%10+c%10;
System.out.println(“Sum=”+d);
}
}
15. Write a program to initialize an int variable a with 76498 and from it extract the first digit and
store it into a variable f and extract the last digit into a variable e and display both these digits.
Ans. class Q15
{
static void main()
{
int a=76498,f,e;
f=a/10000;
e=a%10;
System.out.println(“First Digit=”+f);
System.out.println(“Last Digit=”+e);
}
}
16. Write a program using ternary operator to check whether 27 is a multiple of 3 or not.
Ans.
class Q16
{
static void main()
{
System.out.println((27%3==0)?”Multiple of 3“:”Not a multiple of 3”);
}
}
35 Computer Applications – IX (ICSE Course) Answers