Definations
Definations
ICSE Class X
1. Concepts of Objects:
1. What is meant by OOP concept? Object oriented programming means that more importance
is give to the objects rather than to the procedure to solve a problem. It involves creation of
objects that are very similar to real world objects.
2. Define object? Object is an identifiable entity with some characteristics and behaviour.
Example: CAR Characteristics are wheels, steering, brakes, clutch etc. Behaviour
movement, control functions etc.
3. What are the principals of OOP? Abstraction, Encapsulation, Inheritance, Data Hiding etc.
4. Define Abstraction? Abstraction refers to the act of representing essential features without
including the background details or explanations. Exp: While driving a car we only use steering,
accelerator, brakes etc. and are not worried about the internal mechanism.
5. Define Encapsulation? Also termed as Data Hiding, is a way of combining data and function
(that operates on that data) under a single unit (class). Thus encapsulation hides the data from the
outside world and does not allows direct access of data. Data can be only accessed by functions.
6. What is Data Hiding? Data hiding means that the actual working of an object is hidden from
the outside world. We are able to drive a CAR without knowing much of its internal details that
are encapsulated, and can be only used through some functions.
7. What is a Method? It is a function, which represents the specific behavior of an object.
8. What is a Message? How do objects interact with each other? Message is a way of sending
and receiving information to and from another object. When the object needs to interact with one
another, they pass information to one another known as message passing.
9. How is Encapsulation related to Abstraction? Encapsulation is a way to implement data
abstraction, by hiding the details of implementation of an object.
2. Introducing Classes:
1. Define Class? Class represents a set of objects that share common characteristics and
behaviour. Class is an object factory. Exp: A Class of Cell Phone have many objects like: Nokia,
Samsung, Motorola etc.
2. How are objects related to a class? Objects are instances of a class. The object represents the
abstraction represented by the class in the real sense.
3. What is object factory? Why is class termed as object factory? An object factory is a
producer of objects. It has information regarding the type, characteristics and behavior of an
object.
Class is termed as an object factory because it contains all the statements needed to create an
object and the operations that the object will be able to perform.
3(a) What is Modularity? The act of partitioning a program into individual components is
called Modularity. 1. It reduces complexity 2. Creates a well defined documented boundaries
within the program
4. Define Inheritance? Inheritance is the process by which one object acquires the properties of
another object. It also allows creation of new class from an existing class and adds properties to
the new class. Example: Alsatian is a part of class DOG, dog is a part of class MAMMAL and
mammal comes under the class ANIMAL. Here Alsatian inherits the characteristics of dog, dog
inherits the characteristics of mammal and mammal inherits the characteristics of animal class.
The main class whose properties are inherited by another class is known as the Base class, Parent
class or the Super class. The inherited class is known as the sub class, child class or the derived
class.
5. Define Polymorphism? Polymorphism allows two or more classes or function to respond to
the same message in different ways. It is a process where the same message can be processed in
different ways depending on the type of data they act upon. Example: If a message of adding two
values is given to two different functions having different data types they will produce different
results. ADD integer values 5 + 4 = 9. ADD string values “5” + “4” = “54”. Polymorphism is
also termed as function overloading.
6. What is instance variable and class variable? Instance variable is an object that contains the
information about the class variables and class functions. It is an instance of class. Class
variables are individual variables of different types. Their behaviour is represented by the
functions of that class.
7. What are Global variables? Variables declared within the scope of the class are global
variables. They are of two types Static and Instance (nonstatic/Class) variables.
Static Variable: These are the data members that are declared once for the class. All object of
the class type share these data members as there is a single copy of these variables available in
the memory. Keyword ‘static’ in the variable declaration makes the variable static.
Instance Variables: These are the data members that are created for every object of the class.
3. Introducing JAVA
1. Explain – “Java is both a programming language and a platform”? As a programming
language we can create many computer applications. As a platform java is designed to run highly
interactive, dynamic and secure applications for computers in a network.
2. Who developed Java? What is the initial name of Java? James Gosling in 1991 developed
Oak (Java) language for programming intelligent consumer electronic devices.
3. What do you understand by Byte Code or Java Byte Code? After compilation Java does
not produces native executable code for a particular machine but it produce a special format
called byte code. It uses a 2-byte character code called Unicode, which is platformindependent
i.e. recognized by all types of platforms whether dos, windows, Linux, Unix etc. A java Byte
Code is a machine instruction for Java processor chip called Java Virtual Machine (JVM).
Unicode supports 128 characters same as common ASCII character set, next 128 characters same
as upper 128 characters of ISO Latin-1 which are extended ASCII character set. Other are 65280
characters.
4. What is source code? A program written by a programmer in high level language (English
language) called the source code.
5. What is machine language code? Is a language which the computer can understand?
After compiling the source code we get the machine code for that program which is understood
by the computer.
6. What is High Level Language & Low Level Language? High Level Language is simple
English language in which the program is written which is then converted by the language
processors into Low Level Language known as machine code.
7. Define compilation? The process of converting source code to machine code is called
compilation.
8. Define compiler and Interpreter? Compilation is done by language processors like
compilers (COBOL) and interpreters (Basic). Compilers convert the whole program in one go
from HLL to LLL, so compilation is fast but debugging (finding and rectification of errors) is
difficult as it displays a list of errors. Interpreters convert the program from HLL to LLL line-by-
line, so compilation is slow, debugging is easy as errors are detected and corrected one by one.
9. What do you understand by Native Executive Code? The machine code produced after
compilation is called native executable code. It depends a lot on the platform it is executed
upon. Thus different platforms are required to run different machine codes.
10. Explain - Java interpreter or Java Virtual Machine (JVM)? A java Byte Code is a
machine instruction for Java processor chip called Java Virtual Machine (JVM). Java interpreter
running on any machine appears and behaves like a “virtual” processor chip. [Virtual – appears
real though unreal, gives a feel of being real.]
11. Give characteristics (features) of Java? Write Once Run Anywhere (WORA) Light weight
code – no huge coding is required even for large programs.
Security – It offers many security features.
Build in Graphics - features are offered by java.
Object Oriented Language – so very near to real world
Supports Multimedia – java is suitable to process video, audio, animation and graphics in
Internet environment.
Platform Independent – change of platform does not affect the original java program or
application.
Open product - freely available to all.
12. Explain “Write Once Run Anywhere” (WORA) feature of Java? This means that a
program once written in Java Language can be easily executed and run on any platform.
13. What is a comment? Comments are English statement written to explain the code / logic
of the program. The computer ignores them during compilation. Comments help in
understanding the logic of program and documenting the program. The different ways of
giving the comments are:
// is used for giving single line comment,
/* */ is used for giving multi line comment. Comment can be of more than two lines.
/** */ is used for documentation
14. Name the types of Java Programs? Java Internet Applets and Stand Alone applications.
7. Functions
What is a function or method? A function is a program having sequence of executable
statements, which performs a specific task. Functions are also known as methods, procedures,
sub-programs or sub-routines. A function may or may not return a value. A function can be a
part of a class or can be a part of any other class or function.
Give advantage of using functions in a program?
Handles complex problems easily. Problem is divided into small manageable tasks. Hides low-
level (less important) details. Reuses portions of code again and again without retyping them.
What type of function does not returns a value? Function with type void does not returns a
value.
How many values can a function return at a time? Only one value can be returned by a
function at a time.
What are the points kept in mind if the function returns a value? Types of value returned
by function? If the function returns a value then its return type should either int, float, double,
char, String or boolean. The function should end with a return statement followed by a variable
of the same type as returned by the function.
What is the role of return statement in the function? Return is an unconditional jump
statement. (1) Placed in a function the return causes an immediate exit from the function and the
control is passed back to the function from where it was called. (2) It returns a value to the
calling code.
What is meant by arguments or parameters? Arguments or parameters are those variables
that appear in function definition and are passed through function.
Can a function be without arguments? Give example. Yes a function can be without
arguments i.e. without parameters where no variables are passed through function. Example:
void DrawLine() { for(int I=1;I<=80;I++) System.out.print(“-“); } In this function no arguments
are passed and it will draw a line when ever called.
What are conventions that should be followed while method naming? While naming a
function we should see that name is meaningful and self descriptive. Function having multiple
words are joined and begin with uppercase letter. Function name generally begin with a verb.
Examples: printReportCard(); getMarks(); readData(); findFile(); isPrime(); getFactorial();
countVowels();
What is meant by function prototype? Give its importance. A Function Prototype: (i)
describes the function, (ii) tells the program about the type of value returned by the function
(return type) and (iii) tells about the type and number of argument passed (function signature).
What is meant by function signature? The argument passed through function is known as
function signature. int getSum(int a,int b); [ a and b]
How is a function executed or called? Explain with an example. Function can be called by the
following ways:
Calling function of the same class
If the function returns a value: valueVariable = fucntionName();
Function without return value: functionName();
It is to be noted that if the function of the same class is to be called then it can be called just by
giving the function name. But if a function of another class is to be called then an object is
required which is the instance of that class i.e. an object representing a class.
Calling fn. of another class
If the function returns a value: value variable=obj.fnName();
Function without return value: obj.FnName();
Where obj is instance of class created by className = new obj className();
What type of function can be used with an expression?
A function that returns a value can be used with an expression while calling.
(K = getSum(a,b) + 50; )
Explain Actual and Formal parameters with the help of an example?
Formal Parameters: Parameters that appear in function definition.
Actual Parameters: Parameters that appear in function call also known as original variables.
//function definition
int getSum(int a, int b) { int c = a + b; return c; }
Formal parameters.
//main function
void main()
{ int n1=10, n2=20;
int sum = getSum(n1,n2); //function calling
} Actual parameters
What type of arguments can be passed through function?
Arguments that can be passed through function are:
Primitive data types: char, byte, short, int, long, float and Reference data types:
objects and arrays.
Explain the two manners of invoking/calling a function?
Function calling is done by two ways:
Calling function by VALUE method: Passing variables/values through function: In call by
value method values of actual parameters are copied into the formal parameters i.e. function
creates its own copy of argument values and works on these values. Whatever changes take place
are not reflected back to the original or actual variables or parameters because function does not
have access to the original variables. This type of calling is useful if original values are not to be
modified.
Calling function by REFERENCE method: passing objects through function: In call by
reference method in place of passing value to the function, a reference of the original variable is
passed which stores the address of memory location of the variable. Thus the formal parameters
become reference to the actual parameters in the calling function. Thus in this method the
function does not creates its own copy but refers to the original values by a different name i.e.
reference. Thus the called function works with the original data and any change in the values
gets reflected in the original variables.
Explain the tree types of functions in terms of value returned by function:
1. Computational functions calculate or compute some value and return the computed value or
result. Example: Math.pow(x,y)
2. Manipulative function manipulate information and returns a success or failure code denoted
by 0 or 1; true or false. Example: string1.compareTo(string2)
3. Procedural function performs an action without any return value. Example:
System.out.println();
Types of Functions in terms of modifying the formal parameters? Diff. of Pure and Impure
function?
A pure function talks objects and primitives as arguments and does not modify them. The return
value of a pure function is either a primitive or a value of a new object created inside the
function.
An impure function changes / modifies the state of received object.
Explain Function overloading? Give Example.
What is function overloading? We can define several functions by the same name in the same
class which are differentiated by the type or the number of argument passed through function.
Example of function overloading:
class overload
{ int area(int s);
int area(float s);
int area(int l, double b);
int area(float h, double b);
}
Can there be many functions by the same name in a class? If yes what is the name give to
this concept? Yes there can be more than one function by the same name in a class. This
concept is known as function overloading (polymorphism)
8. Constructors
What is a constructor? Give example.
A constructor is a member function having a same name as that of its class. Constructor have no
return type, not even void. Exp Class xyz { int a, b; xyz( ){ a=10, b=30; } void display ( ) {
System.out.print(a+”\t”+b); } }
What is the use of constructor in a class? A constructor is used to initialise the objects / data
members of that class with a legal initial value.
How is a constructor executed or called? A constructor is executed on creation of an object for
that class.
Can a constructor return any value? Constructor cannot return value, as it has no return type,
not even void.
Explain the types of constructors with example: (A) Parameterised and (B) Non-
Parameterised.
A constructor that receives parameters is a parameterised constructor. The data members of that
class are initialised by the passed parameters.
Class xyz { int a, b; xyz(int n1, int n2) ){ a=n1, b=n2; } void display ( ) {
System.out.print(a+”\t”+b); } }
A constructor that receives no parameters is a non-parameterised constructor. The data members
of that class are initialised by default values or by given values.
Class xyz { int a, b; xyz( ){ a=0, b=0; } void display ( ) { System.out.print(a+”\t”+b); } }
Why we should define a constructor under the public section of a class? A constructor
should be defines under the public section of a class so that its objects can be created in any
function.
What is a default constructor? The compiler supplies a default constructor if it is not explicitly
defined. The default constructor does not passes any arguments and it initialises the data
members by any dummy values.
Explain Constructor overloading with the help of an example? When we have more than one
constructor having different types and number of parameters in a class then its is known as
constructor overloading.
class overLoad
{ static int a, b; static double c;
overLoad() // 1. non-parameterised constructor
{ a=0; b=0; c=0.0; }
overLoad(int x) // 2. parameterised constructor
{ a=x; b=x; c=0.0; }
overLoad(int x, int y, double z) // 3. parameterised constructor
{ a=x; b=y; c=z; }
void display() { System.out.println(a+"\t"+b+"\t"+c); }
void main()
{ overLoad ob1=new overLoad(); // # 1 constructor is called
display(); overLoad ob2=new overLoad(3); // # 2 constructor is called
display(); overLoad ob3=new overLoad(3, 6, 9.5); // # 3 constructor is called
display();
} } // Get the output for the above program code
What is the use of the this keyword? Explain with an example. Sometimes it happens that
names of data member and the parameters passed through the constructor are same, i.e. the name
of formal parameter or local variable is same as data member name of class. In that case the
compiler will not be able to know as to which object / variable to manipulate. Such type of
problem can be removed using the this keyword with the data members of the class. Example:
PROBLEM
class Box
{ int width, height, depth;
Box (int width, int height, int depth) // parameterised constructor
{ // now problem is which variable is being initialised
width = width; height = height; depth = depth;
}
// SOLUTION the above constructor should be written using this keyword as:
Box (int width, int height, int depth) // parameterised constructor
{ // Data members are referred by this operator
this.width = width; this.height = height; this.depth = depth; }
Name some packages provided by Java? Packages are extensive library of pre-written classes
that can be used in the programs. These classes are divided into groups called packages. Exp:
java.applet; java.io (java input/output package); java.lang (java language package); java.util (java
utility package)
Encapsulation (Chapter 11) Encapsulation is termed as Data Hiding, is a way of combining
data and function (that operates on that data) under a single unit (class). Thus encapsulation hides
the data from the outside world and does not allows direct access of data. Data can be only
accessed by functions.
Visibility Modifiers: this defines which function or method is able to use this method.
Public : It can be called from outside the class also.
Private : Accessible within the class.
Protected : Methods in this class and the methods in any subclasses may use this method.
Scope and Visibility of a Variable/Object/class/function? The scope & visibility of a
variable/object/ class/function is limited to the area within which it is declared. Area within
opening and closing brasses i.e.{ }.
Exp: class xyz { int a; void main { int b; int accept() { int c; } } int display() { } }
Scope of variable a is limited within the { } of class xyz. It can be used in function main(),
accept(), display().
Variable b declared within { } of main() can be used in function main(), accept() but not in
display();
Variable c declared within { } of accept() can only be used within function accept() and not in
any other fn.
The function accept() can only be used within main(), as it is declared within { } of main()
function.
Global Variable: Class variable which is available to the entire class.
Local Variable: Variable declared inside a method or block { }
Variable a is known as global variable as it can be used within all function of the class area { }
Variable b is a local variable of function main(); Variable c is a local variable of function
accept().
11. Arrays
Define array? Give syntax to declare array? An array is a collection of variables of the same
type that are referenced by a common name. An array contains cells. Each of them is given a
unique positive integer number beginning from 0,1,2,3…. and so on, which denotes the cell
position known as index number. This number is enclosed within bracket (i.e. arr[0], arr[1],
arr[2], arr[3],…..) known as subscripted variable. So we can say that array is a group of single
subscripted variables. Each single subscripted variable can hold a value as stored in a normal
variable. Single dimension array consists of a row or a column. Type ArrayName[]=new type
[size]; Double dimension array consists of row and column. Type ArrayName[][]=new type
[SizeRow][SizeCol]. Type can be int, float, double, char, String. Size can be any integer positive
value.
How do we initialise single and double dimension arrays?
Initialise numbers 3,5,7,8,9 in an array? int num[ ]={3,5,7,8,9};
Initialise names “alok”, “john”, “sita”, “ram” in an array? String name[ ]={ “alok”, “john”,
“sita”, “ram”};
Store ‘k’,’d’,’t’,’m’,’e’ in an array? char ch[ ]={‘k’,’d’,’t’,’m’,’e’};
Store 4,5,3,2,1,6,7,8,9,5,6,2 in 3x4 2-D array? int num[ ][ ]={ {4,5,3,2}, {1,6,7,8}, {9,5,6,2} };
Store “alok”, “john”, “sita”, “ram”, “rita”,”rash” in an 2x3 array? String nam[ ][ ]={ {“alok”,
“john”, “sita”}, {“ram”, “rita”,”rash”} };
Values in an array can also be stored using a loops using input statements. We can also pass
arrays through functions, to store the values. Arrays are by default passed by reference.
What is the need or advantage of using array in program?
When large volume of data of same type is to be stored for processing array is the best option.
Values can be reused easily as all the data is referred by a single name. Program code is reduced
and made easy to understand.
What is meant by the size of an array? What is the valid range of indices? The size of an
array is equal to the number of cells referred by the single name. The valid range of indices is 0
to size-1. All element of an array are addressed using the name of the array and the subscripts
0,1,2,...n-1. If array is Z[5] then legal elements are Z[0], Z[1], Z[2], Z[3], Z[4]. Subscripts <0 or
>=n are illegal and will be referred as out of bound subscripts.
What is the maximum cell address in an array having 10 cells? Ans: 9
Give difference between linear and binary searching? In linear searching the element to be
searched is searched scanning each and every cell from 0. In binary searching the array elements
should be arranged in some order. The value to be searched is first checked in the mid of array, if
not then it is searched in the mid of that half to which it belongs and the process is repeated until
value is found. This is faster then linear search.
Give difference between selection and bubble sorting? Sorting referrer to arranging the value
in some order: ascending or descending order. If array contains 5 cells then, in selection sort the
values are compared on one to one bases. [0] is compared with [1],[2],[3] and [4], then [1] is
compared with [2],[3],[4] then [2] is compared with [3], and [4] and lastly [3] is compared with
[4]. This process is repeated for 5 times in case of array having size 5. In bubble sort the values
are compared in pairs. [in an array of size 5 [0] is compared with [1], [1] with [2], [2] with
[3] and [3] with [4]. This process is repeated 5 times. In bubble sort as the comparison is done in
pairs thus the sorting becomes faster.
In a double dimension array the first subscript represents (row/col)? First subscript
represents rows.
Give the advantages and disadvantages of using arrays? By the use of arrays large volume of
similar type of values can be referred by a single name. It is easy to declare and use. The
program code can be easily managed. The program code becomes small and easy to understand.
Array elements can be randomly and directly accessed by providing the index number. The only
disadvantage is that before using the array the size is to be known and we have to be careful that
the array is declared to hold the largest possible group of data.
What are the points to be kept in mind while giving the size of an array?
While specifying the size of an array we have to be careful that the value should be a positive
and integer. As the indexing of cells begins from zero so the last cell index is always one less
than the size specified.
Functions:
Write a function, which returns Boolean type true if the passed number is prime otherwise
returns false?
Write a function which prints a line of ‘n’ number of stars i.e. ‘*’.
Write a function to find the maximum of two numbers.
Program to show how to call a function of another class.
Complete the following functions:
int getFactorial(int) //fn. To return the factorial of a number
int countFactors(int) //fn. To return the count of factors of a number
int sumOfFactors(int) //fn. To return the sum of the factors of a number
int sumOfDigits(int) //fn. To return the sum of the digits of a number
int reverse(int) //fn. To return the reverse of a number
boolean isVowel(char) //fn. To check if a character is a vowel or not
boolean isPrime(int) //fn. To check if a number is a prime or not
boolean isPerfect(int) //fn. To check if a number is a perfect number or not
int isLeap(int) //fn. To check is a year is a leap year or not. Return 0 or 1
void spaces(int) //fn. That prints a given number of spaces
void ascendNum(int[ ]) //fn. To arrange array of numbers in ascending order
void alphaOrder(String[ ]) //fn. To arrange names in an array in alphabetic order
void meritList(name[], int mks[]) //fn arranges name in descending order of marks
int countSpaces(String) //fn. That returns the count of spaces of a string
Program to print twin prime nos. between 1 to 100 (use function isPrime(int) )
Program to print all special nos. between 1 to 500 (use function getFactorial(int) )
Program to check if the inputted number is magical no (use function sumOfDigits(int) )
Program using function that returns an absolute value for any passed integer number.
Program to show that different objects of the same class store different values
Single Dimension Array:
1. Input N values in an array and find the sum and average of all the elements.
2. Arrange values in ascending and descending order using selection / bubble sort.
3. Search a given value using liner or binary search technique.
4. Search for maximum and minimum value along with its position.
5. Input names and print the name of maximum and minimum length.
6. (a) Input names and marks in two different arrays and print the name who
got the highest and the lowest marks.
(b) Search a given name and print its marks.
(c) Print all the names getting marks above 70%.
(d) Arrange names according to marks in descending order.
(e) Arrange names in alphabetic order along with corresponding marks.
7. Quantity and rate for N products is stored in arrays and print a bill.
Double Dimension Array:
1. Print values in matrix form. Printing different given format.
2. Transposing of matrix.
3. Print matrix along with sum of rows and columns.
4. Print sum of main and secondary diagonal.
5. Sum of boundary elements, corner elements, elements above & below main diagonal.
6. Printing of elements above and below the main diagonals.
7. Search a value and print the row and column location.
8. Modify the cell according to row and column address.
9. Search and print the prime, Armstrong, automorphic etc nos.
10. Print the values that are at prime location.
11. Adding and subtracting the elements of 2-D array.
Series:
1. Fibonacci series and locus series.
2. Sum of numbers 1 to n
3. Product of numbers 1 to n (Factorial)
4. 1 + 3 + 5 + 7 + 9 + …… n
5. 2 + 4 + 6 + 8 + 10 + …..n
6. ½ + 1/3 + ¼ + 1/5 + 1/6 + …. 1/n
7. ½ + 2/3 + ¾ + 4/5 + 5/6 + ….n/n+1
8. 1 + x/2 + x/3 + x/4 + x/5 + ….x/n
9. 2! + 3! + 4! + 5! + 6! + …. N!
10. 1 + 3/2! + 4/3! + 5/4! + ….. n-1/n!
11. 2 – 3 + 4 – 5 + 6 – 7 + 8 – 9 …. N
12. (1+2) + (1+2+3) + (1+2+3+4) + (1+2+3+4+5)….. (1+2+3+4+5+……+n)
13. 1 + 3 – 5 + 7 – 9 + 11 – 13 + …… n
Patterns:
1. 1 12 123 1234 12345
2. 1 22 333 4444 55555
3. 12345 1234 123 12 1
4. 54321 4321 321 21 1
5. 5 45 345 2345 12345
6. 5 54 543 5432 54321
7. 1 21 321 4321 54321
8.
*
**
***
****
*****
*****
****
***
**
*
9.
1
121
12321
1234321
123454321
10.
0
101
21012
3210123
432101234