Nishanth X D Computer Applications Home Test
Nishanth X D Computer Applications Home Test
Question 2 [5]
Tick the correct option to fill in the blank space.
1. ________ of a class is simply an object that has been created based on the class description.
a) Blueprint b) Design c) Object d) An instantiation
2. ______ notation is an expression used to get an access to the instance variables and methods
inside a given object
a) Arrow b) Colon c) Semicolon d) Dot
3. In a function, the ___________ contains a collection of statements that define what the
method does.
a) Return statement b) Parameter’s list c) Method body d) None of these
4. A class is called an ___________ because it creates objects and used them.
a) Object destructor b) Object factory c) Object modifier d) Object updater
5. Unlike instance variables, whose values are stored in the instance, ______ values are stored
in the class itself.
a) Class variable’s b) Global Variable’s c) final variable’s d) side variable’s
Question 3
a) z=176
b) z= 175
c) z=178
d) z=174
2. if int p=5, q=19, then int n= (q-p)>(p-q)? (q-p) :(p-q);
a) n= 15
b) n =14
c) n =10
d) n=16
3.
int a,b;
for(a=6,b=4;a<=4;a=a+6)
if(a%b==0)
break;
System.out.println(a);
a) 4
b) 6
c) 5
d) 0
4. int a=18, b=12;
boolean t=(a>20&&b<15)?true:false;
a) true
b) false
5. if(a>10&&b>10)
R=a*2;
else
R =b*3;
}
What will be the value of r if a= 20 , b=10?
a) r= 45
b) r= 200
c) r =30
d) None of these
Question 4
3. A statement terminates the loop and the control moves out of the loop.
Question 5 [5]
a) true b) false
2. 5_$ is a valid identifier.
a) true b) false
a) true b) false
4. A method can accept one or more values as arguments.
a) true b) false
a) true b) false
Question 6 [5]
1. Identify the protoype of a method names as fnFest , which has return type of int , and take
one int argument .
a) int fnFest(int n) b) int fnfest(n) c) int FnFest( int n) d) None
2. What is the output of the following code?
class loop
{
public static void main()
{
int a=0,m=27;
for(a=25;a<=m;a++)
System.out.println("A="+a);
System.out.println("B="+a);
}}
a) A= 25 b) A=25 c) A=25 d) A=25
B=27
System.out.println(“A=” +a);
{ case ‘a’:
case ’e’:
case ‘i’:
case ‘o’:
default : v=’N’;
}
Question 7
void calculate() – To calculate discount on the cost of purchased items, based on following
criteria
import java.io. *;
import java.util.*;
class ShowRoom
{
String name;
long mobno;
double cost;
double dis;
double amount;
----------1-------------
{
name =” “;
mobno =0;
cost = 0;
dis = 0;
amount = 0;
}
void input ()
{
Scanner sc = new Scanner (System.in);
System.out.println(“EnterName:”);
name = sc.nextLine( );
System.out.println(“Enter Mobile number:”);
mobno = sc.nextLong( );
System.out.println(“Enter cost:”);
cost = ___________2________________
}
void calculate( )
{
if (cost <= 10000){
dis cost*5/100;
amount = cost – dis;
}
else if (cost > 10000 && cost < = 20000){
dis =_________________3_________
{
dis = cost*20/100;
amount = cost – dis;
}
}
void display( )
{
System.out.println(“Name : ” +name);
System.out.println(“Mobile No : ” +____________5_________);
System.out.println(“Amount : ” +amount);
}
public static void main(String args( ))
{
_____________________6________________________
ob.input( );
ob.calculate( );
ob.display( );
}
}
1.
a) ShowRoom( )
b) ShowRoom( );
c) showroom ( )
d) showroom ( );
2.
a) sc.nextLong();
b) sc.nextDouble();
c) sc.nextInt();
d) sc.next();
3.
a) cost* 10/100;
b) cost*5/100;
c) cost*15/100;
d) cost *20/100;
5. a) Mobno
b) mobno
c) MobNo
d) MOBNO
Question 8
Write a program to input a number. Display the product of the successors of even digits of the
number entered by user.
Input: 2745
Output: 15
[Hint: The even digits are: 2 and 4
The product of successor of even digits is: 3*5= 15] [6]
import java.util.Scanner;
public class evensuccessor
{
public static void main()
{
Scanner in = new Scanner(System.in);
System.out.print("Enter the number: ");
int num = in.nextInt();
int orgNum = ___________1__________;
int prod = ____________2_____________;
while (num != 0)
{
int digit = num % 10;
num /= 10;
if (________3_________)
prod = ________4_________
}
if (______________5_________)
1.
a) num
b) Num
c) Num;
d) num;
2.
a) 0
b) 1
c) -1
d) None
3.
a) digit % 2 = = 0
b) digit / 2= =0
c) digit%2! = 0
d) digit /2! =0
4.
a) prod * (digit *1);
b) prod * (digit+ 1);
c) prod +(digit + 1);
d) prod * (digit - 1);
5.
a) prod = = 1
b) prod = 1
c) prod = = 1;
d) prod= =0
6.
a) Orgnum
b) prod
c) num
d) none
Question 9
Design a class to find the factorial of a number. [4]
import java.io.*;
class fact
{
void _________1_________(int n)
{
int i;
int f=1;
for(i=1;i<=n;i++)
{
___________2__________
System.out.println("Factorial of "+n+"is="+f);
}
}
public static void main(__________3________)
{
fact nfactorial = new fact();
__________4________ factorial(x);
}
}
1.
a) factorial
b) Factorial
c)nFactorial
2.
a) f=f+i;
b) f=f*i;
c=f=f-i;
3.
a) int x;
b) int n;
c) int f;
4.
a) factorial .
b) factorial .
c)nfactorial .
Question 10
Read the paragraph given below and answer the questions given below: [4]
Case study
All modern programming languages provide ways for programmers to leave helpful notes,
reminders , or documentation within their source code. These reminders are known as comments.
Comments are not actually statements because they are skipped by the compiler and do not exist
at runtime.Although the compiler ignores comments, the software developer should not ignore
them. Java provides developers with three separate ways to add comments to their code. The
following symbol are used to denote comments in Java:
• / *……..*/ These delimiters are used to surround single or multiple line comments
• // This delimiter denotes a single line comment
• /**……….*/ comments used by Javadoc, a java documentation tool provided with the
Java Developer Kit (JDK) from Sun Microsystems.
a) They do not exist b) They are processed c) They are executed d) None of these
4) Which part of Java system uses the /** ………. */ system of making comments?