X - PreBoard 2023 Solved
X - PreBoard 2023 Solved
Question 1: [20]
Choose the correct answer and correct option.
(i) Data hiding results into :
(a) Abstraction
(b) Modularity
(c) Polymorphism
(d) Inheritance
(ii) Which OOP concept is implemented by function overloading :
(a) Encapsulation
(b) Abstraction
(c) Polymorphism
(d) Inheritance
(iii) Class String is present in which package ?
(a) java.util
(b) java.lang
(c) java.io
(d) java.awt
(iv) The size of data type long in bytes is :
(a) 2
(b) 4
(c) 8
(d) 16
(v) The return of Math function rint( ) is :
(a) int
(b) float
(c) double
(d) long
(vi) Which access specifier truly implements the concept of Encapsulation ?
(a) private
(b) public
(c) protected
(d) default
(vii) The ASCII code of alphabet D is :
(a) 98
(b) 100
(c) 68
(d) 69
(viii) The return type of string handling function equalsIgnoreCase( ) is :
(a) int
(b) char
(c) double
(d) boolean
(ix) Which of the following statement is Not True for the constructor function :
(a) It does not have any return type value
(b) It can be called by sub-class
(c) It is called at the time of object creation
(d) It initializes the data members of the class
(x) Conversion of primitive data type into its object is called :
(a) Autoboxing
(b) Unboxing
(xi) Base type of an array is :
(a) size of an array
(b) data type of array
(c) location of an element within array
(d) None of the above
(xii) A bundle of similar classes is called as
(a) Object
(b) Packed class
(c) Package
(d) Array
(xiii) A static method is also called as
(a) instance method
(b) class method
(c) abstract method
(d) defined method
(xiv) Type casting is :
(a) Implicit conversion
(b) Explicit conversion
(c) Type promotion
(d) Default conversion
(xv) A __________ method/variable is accessible only inside a particular package:
(a) private
(b) public
(c) protected
(d) default
(xvi) The parent class of a class is also called as :
(a) base class
(b) super class
(c) sub class
(d) both (a) and (b)
(xvii) If value of x = 15.25 and y = - 4.28 , select the output of the following expression:
Math. abs(Math.rint(x) +Math.floor(y))
(a) 11.0
(b) 10.0
(c) 12.0
(d) 9.0
(xviii) Which of the following in Not True about constructor function ?
(a) Constructor have the same name as that of the class
(b)` Constructors initializes the object
(c) Constructors can be more than one .
(d) Constructor can return only 1 value.
(xix) The Wrapper classes are available in package_____ :
(a) java.lang
(b) java.util
(c) java.io
(d) java.class
(xx) The objects can be passed as parameter to a user defined method by :
(a) call by value method
(b) call by reference method
(c) can not be passed
(d) both (a) and (b)
Question 2:
(i) Write the name of classes containing the following functions: [2]
a) parseInt( ) : class Integer b) nextLine( ): class Scanner
c) endsWith( ) : class String d) isLetter( ) : class Character
(ii) Write java expression for the following arithmetic expression : [2]
Y
| X + 2XY |
Math.abs( Math.pow(X,Y) + 2*X*Y)
(iii) Define Autoboxing and Unboxing. Give one example of each. [2]
Autoboxing : It refers to the conversion of a primitive data type into its respective
object. For example : int a = 10;
Integer obj = a;
Unboxing : It refers to the conversion of a wrapper class object into its respective
primitive data type . For example : Character ob = ‘A’;
char ch = ob;
(iv) Write a function prototype for a function check ( ) that takes one string and a
character as parameter and returns true or false. [2]
Answer : public boolean check( String str , char ch)
SECTION B
Question 3 [15]
Define a class Wages having following description:
Data members: String n : To store name
int h : To store total hours of working in a week
for which wages are to be paid
double rate : Rate of wages
double w : To calculate total wages
member functions:
input( ) : To input name and hours of working
calwage( ) : To calculate wages according to conditions
display( ) : To print all the details of employee and total wages
Write a program to compute wages as per the following conditions:
Number of hours Rate
Upto 40 hrs. Rs. 100 per hour
VDT
NAME TYPE PURPOSE
n String To store name
h int To store working hours
rate double To store rate per hour
w double To calculate total wages
Question 4 [15]
Write a program to input any integer number and check if it is PrimePalindrome number or not.
A primepalindrome is a number which is prime as well as palindrome both.
For example : 131 which is both prime and palindrome .
Answer : import java.util.*;
class PrimePalindrome
{ public static void main(String args[])
{ Scanner sc = new Scanner(System.in);
int n, num, rev, flag,dig; // variable declaration
System.out.println(‘ Enter any integer number =”);
n = sc.nextInt(); // input
flag=0;
for (int i= 2 ; i < n; i++)
{ if (n % i ==0) flag =1;
}
rev=0;
num = n;
while (num >0)
{ dig = num %10;
num= num/10;
rev = rev *10 + dig;
}
if ( flag==0 && rev== n)
System.out.println(“ Number is PrimePalindrome”);
else
System.out.println(“ Number is not PrimePalindrome”);
} // end of fn main()
} // end of class
VDT
NAME TYPE PURPOSE
n int To store number
num int To store value of n for working
rev int Reversed number
dig int Chopped digit
flag Int Variable to check divisibilty
Question 5 [15]
Write a program to overload a function find( ) as follows:
● void find(String S1, String s2) : To compare the two strings if they are same alphabetically
or not and prints the message accordingly.
● void find(String str, char ch1, char ch2): To replace all the occurrences of character ch1 by
another character ch2 in the string str and to print the modified string.
Write function main( ) also to create the object of class and to call above mentioned functions.
Answer : import java.util.*;
class Overload
{ public void find (String S1, String S2)
{ if (S1.equals(S2))
System.out.println(“ Both Strings are same alphabetically”);
else System.out.println(“ Both Strings are not same alphabetically”);
} // end of fn
Question 6 [15]
Define a class Numbers to store number of integers in an array in ascending order.
Now ask the user to input any particular number. Find if that number is present in the array
or not by using Binary Search Technique. Print the array and also the message if the number
is found or not.
VDT
NAME TYPE PURPOSE
arr[] int Array variable
n int Size of array
val int Value to be searched
f int First location
l int Last location
m int Middle location
flag int Variable used to check
i Int Loop control variable
Question 7 [15]
Write a program to accept a word and convert it to new word by replacing the vowels with the
letter just following it. Print the modified word.
For example: Input: computer
Output: cpmpvtfr
VDT
NAME TYPE PURPOSE
str String To store word
newstr String To modified word
ch char chopped character
i int Loop control variable
Question 8 [15]
Write a program to input a set of names in 1-D array of strings. Sort the name list in alphabetical
order using Bubble Sort technique. Print the sorted list of names.
Answer :
import java.util.*;
class Sort_Names
{ public static void main(String args[])
{ Scanner sc = new Scanner(System.in);
int n;
System.out.println(“ Enter total names =”);
n = sc.nextInt();
String names[] = new String[n]; // Array declaration
int i, j;
System.out.println(“ Enter names =”);
for (i=0 ; i<n ; i++)
{ names[i] = sc.next(); // Input of names
}
// Bubble Sorting
String temp;
for (i=0 ; i< n-1 ; i++)
{ for (j= 0; j<n-1- i ; j++)
{ if (names[j].compareTo(names[j+1]) >0)
{ temp = names[j];
names[j] = names[j+1];
names[j+1] = temp;
}
} // end of j loop
} // end of i loop
System.out.println(“ Sorted List of Names = “);
for (i=0; i< n; i++)
{ System.out.println(names[i];
}
} // end of fn main()
} //end of class
VDT
NAME TYPE PURPOSE
Names[] String Array to store names
n int Total number of names
i int Loop control variable
j int Loop control variable
temp String Temporary string to swap