Sunteți pe pagina 1din 12

https://sites.google.

com/site/javaprogramsisc/ ICSE Questions


1
1 Write two advantages of using functions in a program. 2010
2 What is the role of keyword void in declaring functions? 2007 2011
3 What are the two ways of invoking functions? 2011
4 Differentiate between call by value or pass by value and call by reference or pass by
2012
reference.
5 Explain the term - "pass by reference". 2007R
6 (i) What is call by value?
(ii) How are the following passed? 2005
a. Primitive types. b. Reference types.
7 What is the difference between a static member function and a member function which is not 2011
static? SP
8 Differentiate between Formal Parameter and Actual Parameter. 2008 2007
9 Explain the function of a return statement. 2006
10 If a function contains several return statements, how many of them will be executed? 2007
11 Name the keyword that causes the control to transfer back to the method call. 2009
12 Define an impure function. 2006
13 Differentiate between pure and impure function. 2009
14 Write the function prototype for the function “sum” that takes an integer variable(x) as its
2009
argument and returns a value of float data type.
15 Give the prototype of a function check which receives a character ch and an integer n and
2010
returns true or false.
16 Give the prototype of a function search which receives a sentence sentne and a word wrd
2011
and returns 1 or 0.
17 Enter any two variables through constructor parameters and write a program to swap and
2005
print the values.
18 Create a class with one integer instance variable. Initialize the variable using:
2012
(i) default constructor (ii) parameterized constructor
19 What is a constructor? When is it invoked? 2014
20 State the difference between Constructor and Method. 2013
What is the difference between a constructor function and a member function of a class? 2005
21 What is a default constructor? 2006
22 Why do we need a constructor as a class member? 2007
23 What is a parameterized constructor? 2007R
24 State two features of a constructor. 2010
25 Name the Java keyword that:
(i) indicates that a method has no return type. 2013
(ii) stores the address of the currently – calling object.
26 What does the following mean? Employee staff = new Employee( ); 2008
27 What is the use of the keyword this? 2009
28 Write a Java statement to create an object mp4 of class digital. 2013
29 Create an object for a class Park. 2007R
https://sites.google.com/site/javaprogramsisc/ ICSE Questions
2
1 Pick out the errors and correct them in the given code fragment:
class PickCode
{
private char ch;
private boolean n;
pickcode() 2007R
{
ch= 'C';
n = = true;
}
}
2 Consider the following code and answer the question that follow:
class academic
{
int x, y;
void access( )
{
int a, b;
academic student = new academic( );
2009
System.out.println(“Object created ” );
}
}
(i) What is the object name of class academic?
(ii) Name the class variables used in the program.
(iii) Write the local variables used in the program.
(iv) Give the type of function used and its name.

3 In the program given below, state the name and the value of the
(i) method argument or argument variable
(ii) class variable
(iii) local variable
(iv) instance variable
class myClass
{ int y = 2;
public static void main(String args[ ])
{ myClass obj = new myClass( );
System.out.println( x );
2012
obj.sampleMethod( 5 );
int a = 6;
System.out.println( a );
}
void sampleMethod( int n )
{ System.out.println( n );
System.out.println( y );
}
}
https://sites.google.com/site/javaprogramsisc/ ICSE Questions
3
4 Consider the following class:
public class myClass
{
public static int x = 3, y = 4;
2014
public int a = 2, b = 3;
}
(i) Name the variables for which each object of the class will have its own distinct copy.
(ii) Name the variables that are common to all objects of the class.
5 What will be the output of the following code when function xy() is executed:
class abc
{
final int x=10;
int y=20;
public void xy()
{ System.out.println("Value of x and y "+ x + y);
int x=50;
ax(x);
System.out.println("Value of x and y "+ x + y);
}
void ax(int x)
{ System.out.println("Value of x and y "+ x + y);
int t=x;
x=y;
y=t;
System.out.println("Value of x and y "+ x + y);
}
}
6 Give the output for the following:
public boolean fun (int a)
{ int c = a% a++ + ++a - ++a;
System.out.println (c) ;
boolean d = false ;
return d ;
}
What will be the output and the returned value of the above defined method for fun (2)
7 Explain the concept of constructor overloading with an example. 2011
8 Explain function overloading with an example. 2006
9 Which OOP principle implements function overloading? 2007
10 When there are multiple definitions with the same function name, what makes them different
2009
from each other?
11 What is meant by private visibility of a method? 2006
12 Differentiate between private and protected visibility modifiers. 2010
13 Differentiate between public and private modifiers for members of a class. 2012
14 What is the scope of the keyword protected in accessing methods? 2007R
15 Explain any two types of access specifier. 2008
https://sites.google.com/site/javaprogramsisc/ ICSE Questions
4
16 Differentiate between base and derived class. 2008
1 Define a class named movieMagic with the following description: 2014
Instance variables/data members:
int year - to store the year of release of a movie
String title - to store the title of the movie
float rating - to store the popularity rating of the movie
(minimum rating = 0.0 and maximum rating = 5.0)
Member methods:
movieMagic( ) - Default constructor to initialize numeric data members to 0
and String data member to ""
void accept( ) - To input and store year, title and rating
void display( ) - To display the title of a movie and a message based on the
rating as per the table below
Rating Message to be displayed
0.0 to 2.0 Flop
2.1 to 3.4 Semi-hit
3.5 to 4.05 Hit
4.6 to 5.0 Super-Hit
2 Define a class named FruitJuice with the following description: 2013
Instance variables/data members:
int product_code - stores the product code
String flavour - stores the flavour of the juice ( e.g. orange, apple, etc. )
String pack_type - stores the type of packing ( e.g. tetra-pack, PET bottle, etc. )
int pack_size - stores package size ( e.g. 200 ml, 400 ml, etc, )
int product_price - stores the price of the product
Member methods:
FruitJuice( ) - Default constructor to initialize integer data members to 0
and String data members to “ ”.
void input( ) - To input and store the product code, flavor, pack type, pack size
and product price.
void discount( ) - To reduce the product price by 10.
void display( ) - To display the product code, flavor, pack type, pack size and
product price.
3 Define a class called mobike with the following description: 2011
Instance variables/data members:
int bno - to store the bike’s number
int phno - to store the phone number of the customer
String name - to store the name of the customer
int days - to store the number of days the bike is taken on rent
int charge - to calculate and store the rental charge
Member methods:
void input( ) - to input and store the detail of the customer
void compute( ) - to compute the rental charge
The rent for a mobike is charged on the following basis:
First five days Rs 500 per day
Next five days Rs 400 per day
Rest of the days Rs 200 per day
void display( ) - to display the details in the following format:
Bike No. Phone No. Name No. of days Charge
https://sites.google.com/site/javaprogramsisc/ ICSE Questions
5
--------- ------------ ---------- ---------- ---------

4 Define a class called Library with the following description: 2012


Instance variables/data members:
int acc_num - stores the accession number of the book
String title - stores the title of the book
String author - stores the name of the author
Member methods:
void input( ) - to input and store the accession number, title and author.
void compute( ) - to accept the number of days late, calculate and display the fine
charged at the rate of Rs 2/- per day.
void display( ) - to display the details in the following format:
Accession Number Title Author
Write a main method to create an object of the class and call the above member methods.
5 Define a class student described as below: 2010
Data members/instance variables:
Name, age, m1, m2, m3(marks in 3 subjects), maximum, average
Member methods:
(i) A parameterized constructor to initialize the data members
(ii) To accept the details of a student
(iii) To compute the average and the maximum out of three marks
(iv) To display the name, age, marks in three subjects, maximum and average.
Write a main method to create an object of a class and call the above member methods.
6 Define a class employee having the following description:- 2008
Data members / int pan to store personal account number
Instance variables String name to store name
double taxincome to store annual taxable income
double tax to store tax that is calculated
Member functions:
input( ) Store the pan number, name, taxableincome
calc( ) Calculate tax for an employee
display( ) Output details of an employee
Write a program to compute the tax according to the given conditions and display the output
as per given format.
Total Annual Taxable Income Tax Rate
Upto Rs 1,00,000 No tax
From 1,00,001 to 1,50,000 10% of the income exceeding Rs 1,00,000
From 1,50,001 to 2,50,000 Rs 5000 + 20% of the income exceeding Rs 1,50,000
Above Rs 2,50,00 Rs 25,000 + 30% of the income exceeding Rs 2,50,000
Output:
Pan Number Name Tax-income Tax
- - - -

7 Define a class Book Store having the following specifications: 2007


Data Member: Name of the book, author, publication and cost. R
Member Methods:
(i) To accept the book details
(ii) To calculate the discount of 13.5% given on all books.
https://sites.google.com/site/javaprogramsisc/ ICSE Questions
6
(iii) To display the book details.
Using a main method and an object call the above methods.

8 Define a class salary described as below:- 2007


Data Members : Name, Address, Phone, Subject Specialization, Monthly Salary, Income tax
Member methods :
(i) To accept the details of a teacher including the monthly salary.
(ii) To display the details of the teacher.
(iii) To compute the annual Income tax as 5% of the annual salary above Rs 1,75,000
Write a main method to create object of a class and call the above member method.

9 Write a Java program to display the menu and perform the following as per the user’s choice
using the functions given below:
(a) Print the sum of all the factors of a number
(b) Check and print if a number is perfect or not. A number is a perfect number if the sum
of all the factors of the number excluding itself is equal to the number.
Use the following to perform the above:
int SumOfFactors(int N) to calculate sum of all factors of N, and return it to the
calling function.
boolean chkPerfect(int Num) to check whether the value in Num is perfect or not
void MyMain( ) to implement user’s choice
10 Write a Java program to input two numbers and print the sum of all the Prime numbers
between them, using the following functions:
int CountFactors(int Num) to return the count of all factors of Num
void AddPrimes( int A , int B) to print the sum of all the Prime numbers between A and
B using the other function of the class.
https://sites.google.com/site/javaprogramsisc/ ICSE Questions
7

11 Design a class to overload a function area( ) as follows: 2014


(i) double area(double a, double b, double c) with three double arguments, returns the area
of a scalene triangle using the formula:
area = √𝑠(𝑠 − 𝑎)(𝑠 − 𝑏)(𝑠 − 𝑐)
𝑎+𝑏+𝑐
where s =
2
(ii) double area(int a, int b, int height) with three integer arguments, returns the area of a
trapezium using the formula:
1
area = height(a + b)
2
(iii) double are(double diagonal1, double diagonal2) with two double arguments, returns
the area of a rhombus using the formula:
1
area = (diagonal1 x diagonal2)
2

12 Design a class to overload a function series( ) as follows: 2013


( i ) double series( double n ) with one double argument and returns the sum of the series,
sum = 1 + 1 + 1 + 1 + …….. + 1
1 2 3 4 n
( ii ) double series( double a, double n) with two double arguments and returns the sum of
the series,
sum = 1 + 4 + 7 + 10 + …….. to n terms
a2 a5 a8 a11

13 Design a class to over load a function polygon( ) as follows : 2012


(i) void polygon( int n, char ch ) with one integer argument and one character type
argument that draws a filled square of side n using the character stored in ch
(ii) void polygon( int x, int y ) with two integer argument that draws a filled
rectangle of length x and breadth y, using the symbol ‘@’
(iii) void polygon( ) with no argument that draws a filled triangle shown below.
Example :
(i) Input value of n = 2, ch = ‘O’
Output : OO
OO
(ii) Input value of x = 2, y = 5
Output : @@@@@
@@@@@
(iii) Output : *
**
***

14 Design a class to overload a function compare( ) as follows: 2011


(a) void compare(int, int) - to compare two integer values and print the greater
of the two integers
(b) void compare(char, char) - to compare the numeric value of two character
https://sites.google.com/site/javaprogramsisc/ ICSE Questions
8
with higher numeric value
(c) void compare(String, String) - to compare the length of two strings and print the
longer of the two

15 Design a class to overload a function num_calc( ) as follows: 2009


(a) void num_calc( int num , char ch) with one integer argument and one character
argument, computes the square of integer argument if choice ch is ‘s’ otherwise finds its
cube.
(b) void num_calc( int a, int b, char ch) with two integer arguments and one character
argument. It computes the product of integer arguments if ch is ‘p’ else adds the
integers.
(c) void num_calc( String s1, String s2) with two string arguments, which prints whether
the strings are equal or not.

16 Write a class with the name volume using function overloading that computes the volume of 2008
a cube, a sphere and a cuboid.
Formula : volume of a cube vc = s * s * s
volume of a sphere vs = 4/3 *  * r * r * r (where  = 3.14 or 22/7 )
volume of a cuboid vcd = l * b * h

17 Using function overloading in Java, design a class Overload which contains the method
Palin( ) to perform the following:
(a) To check whether the number is a palindrome or not. A number is said to be a
palindrome if it reads the same from left to right and vice versa. For example 6226
(b) To check whether a word is a palindrome or not. A word is said to be a palindrome if it
reads the same from left to right and vice versa. For example ARORA
Display the menu to accept choice from the user and perform the above tasks.
18 Write a class TriangleArea in Java that contains the overloaded methods area – one that
accepts the length of the base and the height of the triangle as parameters. The other area
method accepts the length of three sides of a triangle. The two formulae for computing the
are:
Area = ½ * base * height when length and height are given
Area = √(s(s-a)(s-b)(s-c)) when length of the sides are given
where s = (a+b+c)
2
Write the main method that accepts the various inputs from the user and calls the above
methods depending on user’s choice
19 Write a program in Java to design a class Box which contains the following:
Data Members – length, breadth and height
Parameterised constructor – to initialize data members by the values passed
void vol( ) - To compute and print the volume of the box
void sarea( ) - To compute and print the total surface area of the box
Define main method to create the object of the class Box and call the above.
20 Write a program that output the results of the following evaluations based on the number 2006
entered by the user.
(i) Natural Logarithm of the number
(ii) Absolute value of the number
(iii) Square root of the number
(iv) Random numbers between 0 and 1.
https://sites.google.com/site/javaprogramsisc/ ICSE Questions
9
21 Design a class in Java to input name and percentage of a student and print his name and
grade using the following functions:
(a) void InputDetails( String Nm, double Per) - to input name and percentage of a student
(b) void Display( ) – to print the name and grade of a student.

22 AA class in Java named SumPrime contains the following:


Date Members n of int type
c of Boolean type
Methods
accept( ) to accept the value in variable n
find( ) to find whether n is a prime or not
sum( ) to print the sum of all the prime numbers from 2 to n
Write a program in Java to write the code for the above class and to create its object and
execute the above methods.
https://sites.google.com/site/javaprogramsisc/ ICSE Questions
10

EXTRA QUESTIONS
23 A class Telcall calculates the monthly phone bill of a consumer. Some of the members of the class
are given below:
Class name: : Telcall
Data members/ instance variables :
phno : phone number
name : name of customer
n : number of calls made
amt : bill amount
Member functions/methods
Telcall( ) : Parameterised constructor to assign values to data members
void compute( ) : to calculate the phone bill amount based on the slabs
given below
void dispdata( ) : to display the details in the specified format

Number of calls Rate


1 - 100 Rs 500/- rental charge only
101 - 200 Rs 1.00/- per call + rental charge
201 - 300 Rs 1.20/- per call + rental charge
above 300 Rs 1.50/- per call + rental charge
The calculations need to be done as per the slabs.

24 A class quad contains the following data members and member functions to find the roots of a
quadratic equation.
Class name: : quad
Data members/ instance variables :
a, b, c, x1, x2 : float type
Member functions/methods
quad(float, float, float ) : constructor to assign values to the data members.
float discriminant( ) : to return the discriminant [ b2 – 4ac ]
void root_equal( ) : to display the root if both roots are equal
void imag( ) : to display the roots, if roots are imaginary
void root_real( ) : to display the two real, unequal roots
void root( ) : to call other appropriate functions to find the
solution of the problem.
If ax2 + bx + c = 0 is the quadratic equation, then
If b2 – 4ac > 0 – roots are real, unequal
where x1 = -b +  (b2 – 4ac )
2a

x2 = -b -  (b2 – 4ac )
2a
If b2 – 4ac = 0 - roots are real, equal
since x1 = x2 = -b / 2a
https://sites.google.com/site/javaprogramsisc/ ICSE Questions
11
If b2 – 4ac < 0 – roots are imaginary
25 Class Employee contains the following member:
Class name : Employee
Data members/instance variables:
empname : To store the name of employee
int empcode : To store the employee code
double basicpay : To store the basic pay of the employee.

The salary is calculated according to the following rules:


Salary = Basic pay + HRA + DA
HRA = 30% of basic pay
DA = 40% of basic pay
If the employee code for the employee is <= 15 then a special allowance will be added if the salary
is <=15000. The special allowance will be 20% of the salary ( Basic pay + DA + HRA) and the
maximum amount for special allowance will be Rs 2500.
If the employee code is > 15 the the special allowance will be Rs 1000.
Hence the total salary for the employee will be calculated as
Total Salary = Salary + Special Allowance

26 Design a program to calculate the tax for the people living in Utopia. Specify a class taxpayer
whose class description is given below.
Class name : taxpayer
Data members :
int pan : to store the personal account number
char name[20] : to store the name of a person
float taxableinc : to store the total annual taxable income
float tax : to store the tax that is calculated
Member functions :
void inputdata( ) : to enter the data for a taxpayer
void displaydata( ) : to display the data a taxpayer
void computetax( ) : to compute tax for a taxpayer
The tax is calculated according to the following rules :
TOTAL ANNUAL TAXABLE INCOME RATE OF TAXATION
Up to 60000 0%
Any amount above 60000 but up to 150000 5%
Any amount above 150000 but up to 500000 10%
Any amount above 500000 15%
In the main program, create an object of the type taxpayer. Calculate the tax for the taxpayer and
output it in the following format :
Pan No. Name Total Annual Taxable Income Tax

27 Design a program to overload a function rect( )


void rect( int n, char ch ) with one integer argument and one character type argument draw a
filled square of side n using the character stored in ch.
void rect( int l, int b, char ch) With two integer arguments and one character type argument draw
a filled rectangle of length l and breadth b using the character stored in ch
Now output the following pattern by calling this function from the main program.
@@@@@
@@@@@
a
bb
bb
https://sites.google.com/site/javaprogramsisc/ ICSE Questions
12
ccc
ccc
ccc
dddd
dddd
dddd
dddd
28 Design a program to overload a function hline( )
void hline( ) without an argument draws a horizontal line 30 characters long using the
character “-“ to draw the line
void hline( int n) with one integer argument draws a horizontal line n characters long using
the character * to draw the line
void hline(int n, char c) with one integer argument and one character type argument draws a
horizontal line n characters long using the character stored in c to draw the line.
Now output the following pattern by calling this function from the main program.
*
***
*****
*******
*********
------------------------------
A
BB
CCC
DDDD
EEEEE
FFFFFF
GGGGGG

S-ar putea să vă placă și