Few question and answers are given below. Students can expect these type of questions in ICSE 2012 Computer Application examination.
What do you mean by data encapsulation and polymorphism in Java?
Data encapsulation means hiding the data members of an object
using the function members so that the data mebers are prevented from
unauthorized access.
Polymorphism is one of the OOP principles by virtue of which
different operators or different functions exihibit different behavior while
used in different environments. Polymorphism are of three types: Function
overloading, function overring and operator overloading.
What is casting, when do we need it? Give an example.
Casting means converting variables or objects from one type to
another type. Casting are of two types, automatic or implicit casting and
forceful or explicit casting.
Sometimes we work on two variables of same type but the result
required is of different type. In such situation casting is needed.
For example, suppose runs scored by a batsman is stored in
variable ‘a’ and total innings played by the batsman and total notout are
stored in ‘b’ and ‘c’ respectively. Now all these values are of ‘int’ type. We
need to calculate the average score of the batsman. If we use the statement
like double av=a/(b-c); the result would not be accurate. In this situation
explicit casting is needed. Double av=(double)a/(b-c);
Name the package you need to import for using Scanner class object.
Scanner class is stored in util package which is again under java
package.
State the difference between while and do-while loop
While loop is entry control loop while do-while loop is exit
control type of loop. In while loop no semicolon is required after the control
statement but in do-while loop, semicolon after the control statement is a
must.
Constructor is a special function whose name must be same as the
class name. Function name must be different from the class name.
Constructor has no return type, not even void while functions
maust have a return type.
If constructor is not defined in a class, compiler supplies
default constructor. Default constructor means constructor with no argument and
empty body. There is no such case with functions.
Explain any two type of access specifiers
There are four type of access specifiers in java and two of them
are public and private. The specifiers can be used before class name, variable
and function declaration. Public class, function or data member means which can
be accessed from anywhere, even from outside the package where the class is
defined.
Private data members and function members are only accessible
within the class body.
What are the preconditions of binary search?
There are two preconditions of binary search, the first one is
that the elements in the list must be in sorted order and the second
precondition is about the accessibility of the middle location of list
directly. That’s why binary search is applicable only in array.
What is the role of void keyword in declaration of a function
Void keyword in a function specifies that the function will not
return any value to the calling program after execution.
Write the name and syntax of the function which is used to extract
multiple characters from strings.
‘String substring (int start, int end)’ function of String class
is used to extract multiple characters from strings. ‘int start’ denotes the
index from where the sub-string will be extracted and ‘int end’ denotes end
location of the string upto which the characters will be extracted.
Find the output of the following code segments:
int a=0,b=0;
for(a=0;a<=5;a+=2)
for(b=0;b<=a;++b)
System.out.println(“Answer1:”+(++a)+b++);
System.out.println(“Answer2:”+(++a)+b++);
Output:
Answer1:10
Answer1:30
Answer1:42
Answer1:54
Answer2:76
int I,j,arr[]=new int[7];
arr[0]=1;
for(i=0;i<6;i++)
{
for(j=i+1;j>0;j--)
arr[j]=arr[j]+arr[j-1];
System.out.println();
}
Following program segment is to print the the sum of the prime
digits of an entered number:
For example, if entered number is 1872, the output will be – sum
of the prime digitd is 9 ( as 7 and 2 are two prime digits in 1872)
int digit,sum=0,n=1872;
while(n>0)
{
?1?=n%10;
If(digit==2||?2?||?3?||digit==7)
sum=?4?;
n=n/10;
}
System.out.println(“Sum of prime digits is”+sum);
Fill up the statements marked with question mark.
?1?: digit
?2?: digit==3
?3?: digit==5
?4?: sum+digit
What is private visibility of a method
Private function means which can not be accessed from outside the
class body. Private functions can be invoked by other functions defined in a
class only.
Function overloading means where function names must be same and
argument list of the functions should be different. The return type of the
functions can be same or different. Function overloading is possible in same
class as well as in sub classes.
void change ()
{
System.out.println(“Nothing
to change…”);
}
void change ( int a, int b)
{
a=a+b;
b=a-b;
a=a-b;
System.out.println(“Values changed =” + a + “,”+b);
}
What does System.in and System.out refers to
System.in is inbuilt input object where the terminal input value
is stored in byte. System.out is the inbuilt output object whose functions like
println () and print () are used for terminal output.
What is exit control loop? Give example
Exit control loop is that type of loop where body of the loop
appears before the control statement of the loop. Do or do-while loop is an example
of exit control loop. In such type of loop, loop body execution for at least
once is confirmed as the control enters the loop body in the first iteration
with out checking any condition.
What is recursive function, give example
Recursive functions are those specific functions where the
function is called repetadely from a state,ment used within the body of the
function itself. A base value is needed in recursive function to stop the
calling.
Write a statement to import a class ‘Nano’ under the package ‘Car’
which is again under the package ‘Tata’ and Tata is under ‘Indian’ package
import Indian.Tata.Car.Nano;
What will be the output of the following program segment?
String name[]={“Computer”,”Application”};
System.out.println(name[0].length());
System.out.println(name.length);
Second output is 2 as there are two elements in the array name.
class Outt
{
public void av()
{
for(i=0;i<=10;i++)
{
If(i==6)
Break;
}
System.out.println(i);
}
}
Output: 6
Give the output:
TuTOrIaI”.indexOf(‘I’);
Math.rint(-38.96);
Math.abs(4789.45);
Math.max(Math.min(15,25),5);
(int)(“Scholar”.charAt(2));
Math.ceil(-28.25);
“MISSISSIPPI”.lastIndexOf(‘S’);
Math.floor(-524.99);
“suddhashil”.substring(3,4);
Math.sqrt(100);
Output:
5
-39.0
4789.45
15
104
-28.0
6
-525.0
d
10.0
Sir, please help me in the programs:
ReplyDelete1) WAP to find all twin prime numbers from 1 to 100 ( using loop and decision making)
2)A game of throwing dice is played between 2 players in which each player throws a dice until his score adds up to 20. A player is declared winner with the minimum number of throws. WAP.
Please go through this page
DeleteFind the output of the following code segments:
ReplyDeleteint a=0,b=0;
for(a=0;a<=5;a+=2)
for(b=0;b<=a;++b)
System.out.println(“Answer1:”+(++a)+b++);
System.out.println(“Answer2:”+(++a)+b++);
Dear Mr Chakravorty,
I was going through your suggestion for ICSE 2012 for my son who is appearing this year. Will you pleae show the steps of the programme above. Even while running it in Blue J, I got little different result. I failed to understand how in Ist iteration, result came to 10. As per my understanding, after first iteration, i=0,j=0. So result1 should have been +(1)+0=1.Wheher in this iteration, it considers the result as character? Kindly show all the steps.
Regards.
Tamal Bhattacharjee
Shillong, Meghalaya
Output:
Answer1:10
Answer1:30
Answer1:42
Answer1:54
Answer2:76
Dear Mr. Tamal
ReplyDeleteYou are right, the output will be as follows:
Answer1:10
Answer1:40
Answer1:52
Answer1:64
Answer1:76
Answer2:108
Here is the explanation of the outputs.
First output: Here a=0 and b=0. Due to preorder increment operator 'a' is incremented by 1 every time before display. Now 'a' is 1 and 'b' is 0.
So the statement becomes System.out.println(“Answer1:”+1+0); Next both '1' and '0' are converted into string values as 'String toString()' function is called automatically, so in the next step the statement becomes_ System.out.println(“Answer1:”+"1"+"0"); All the string values are next concatenated and the output becomes "Answer1:10".
This is the first iteration of the outer loop.
In the second iteration of outer loop, 'a' becomes 3 as it is being increased by 1 in the statement System.out.println(“Answer1:”+(++a)+b++); This is the last iteration of the outer loop. Now the control enters the inner loop
with 'a' as 3 and 'b' as 0. The first print of second iteration of outer loop is Answer1:40. Now 'a'becomes 4 and after printing 'b' becomes 1. Again the reinitialisation statement '++b' mekes 'b' 2. So the next output is 'Answer1:52'. Next ''b' becomes 4 , incremented by 1 due to postorder increment operator and again incremented by 1 in reinitialisation statement of the inner loop. At the time of next output 'a' is 5 and 'b' is 4, so output is 'Answer1:64'. Similarly next output is 'Answer1:76'and after this display 'a' is 7 and 'b' becomes 8 so natuarally the inner loop condition becomes false. Control goes to the outer loop reinitialisation statement and 'a' becomes 9, the outer loop conditional statement also becomes false.
The statement 'System.out.println(“Answer2:”+(++a)+b++);' is placed outside the loop body so this statement is executed only once and at that time 'a' is 9 and 'b' is 8, the output is 'Answer2:108'
In a short, outer loop executes for two times, the inner loop executes only one time in the first iteration of outer loop and in that time the output 'Answer1:10'is printed. In the second iteration of outer loop, the inner loop iterates for four times and the displays are 'Answer1:40', 'Answer1:52', 'Answer1:64' and 'Answer1:76'.
The last output 'Answer2:108' comes from a statement which lies outside the loops.
Sir.please can you show the coding for addtion of two binary numbers using binary addition method........as soon as you can.....pls sir.........
ReplyDeleteBinary addition program is in my site. Search it.
Deletesir,can you plz explain what is exception handling?
ReplyDeleteException means run time abnormality. Jave provides mechanism to handle such situation if any. There are many techniques to handle such situation.
Deletesir please help me out through array programs!!!!i only want you to give some expected array questions as i am appearing for my board exams soon!!!!!!!!i only need single dimensional array programs and i am sure you would help me out!!!!!1
ReplyDeletePlease go through 'array programs' tag
DeleteDear Mr Chakravorty,
ReplyDeletePl refer problem you put up as below:-
Give the output:
class Outt
{
public void av()
{
for(i=0;i<=10;i++)
{
If(i==6)
Break;
}
System.out.println(i);
}
}
Output: 6
. Answer given by you is wrong. The output will be 0,1,2,3,4,5 in different lines. I also checked in Blue J.
Kindly verify & correct for others.
Regards.
Tamal Bhattacharjee
Have you checked the above program without any change? Actually You have to declare 'int i' above the loop body and the rest will be same as the above statements. The output will be only '6', not 0,1,2,3,4,5 in new lines. There is no println statement within the loop body. Please recheck and let me know.
Delete