Section A: 1. A) Why Is An Object Called An Instance of A Class?

Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 3

Section A

1. a) Why is an object called an instance of a class?


b) What is the use of the keyword import?
c) Write a statement each to perform the following task on a string:
Extract the second last character of a word stored in the variable wd.
d) State four features of a constructor.
e) Give the prototype of a function check which receives a character ch and an
integer n and returns true or false.
2. a) Write four advantages of using functions in a program.
b) Write a statement each to perform the following task on a string: (i) Find and display
the position of the last space in a string s. (ii) Convert a number stored in a string variable
x to double data type.
c) Give the prototype of a function search which receives a sentence sentnc and a word
wrd and returns 1 or 0 ?
d) Explain the concept of constructor overloading with an example.
e) (i) Name the package that contains Scanner class. (ii) Which unit of the class gets
called, when the object of the class is created?
3. a) State the difference between compareTo() and equealsIgnoreCase()
b) Explain the concept of method overloading with an example. 
c) What will be the output of the following program segments?
(i) String s = “application”;
int p = s.indexOf(‘a’);
System.out.println(p);
System.out.println(p+s); 
(ii) String st = “PROGRAM”;
System.out.println(st.indexOf(st.charAt(4))); 
(iii) int a = 0;
if(a>0 && a<20)
a++;
else a– ;
System.out.println(a); 
(iv) int a= 5, b = 2,c;
if (a>b || a ! = b)
c = ++a+–b;
System.out.print(c+ “ ”+a+ “ ”+b); 
(v) int i = 1;
while(i++<=1)
{
i++;
System.out.print(i + “ ” );
}
System.out.print(i); 
d) Differentiate between isUpperCase(char) and toUpperCase(char).
e) What is the difference between a constructor function and a member function of a
class? 
f) What is the difference between a static member function and a member function which
is not static?
Section B (Any Four)
Question 4
Anshul Transport Company charges for the parcels of its customers as per the following
specifications given below:

Class name: ATransport

Member variables:
String name: to store the name of the customer.
int w: to store the weight of the parcel in kg.
int charge: to store the charge of the parcel.

Member functions:
void accept(): to accept the name of the customer, weight of the parcel from the user (using
Scanner class)
void calculate(): to calculate the charge as per the weight of the parcel as per the following
criteria:
WEIGHT IN KG CHARGE PER KG

Up to 10 kg Rs. 25 per kg

Next 20 kg Rs. 20 per kg

Above 30 kg Rs. 10 per kg


A surcharge of 5% is charged on the bill.
void print(): to print the name of the customer, weight of the parcel, total bill inclusive of
surcharge in a tabular form in the following format:
Name Weight Bill Amount
____ _____ ________
____ _____ ________
Define the class with the above mentioned specifications, create a main() method, create an
object and invoke the member methods.
Question 5
Design a class to overload a function sum() as follows:
(i) int sum(int a, int b) to calculate and return the sum of all the even numbers in the range a to b.
Sample Input:
a = 14
b = 16
Sample Output:
Sum = 70
(ii) double sum(double n) to calculate and return the product of the following series:
Product = 1.0 × 1.2 × 1.4 × … × N
(iii) int sum(int n) to calculate and return the sum of only odd digits of the number N.
Sample Input:
N = 43961
Sample Output:
Sum = 13
Write the main() method to create an object and invoke the above methods.
Question 6
Write a program to input a string and convert it into uppercase and print the pair of vowels and
number of pair of vowels occurring in the string.
Example:
INPUT:
“BEAUTIFUL BEAUTIES”
OUTPUT:
Pair of vowels: EA, AU, EA, AU, IE
No. of pair of vowels: 5
Question 7
A String is said to be ‘Unique’ if none of the alphabets resent in the string are repeated.  Write a
program to accept a string and check whether the string is Unique or not.  

Example :-
Input: COMPUTER
Output:Unique String
Input: APPLICATIONS
Output: Not a Unique String
Question 8
Write a menu-driven program in Java for
Choice 1:capitalizes first letter of each word in a string .
Choice 2:capitalizes last letter of each word in a string
Question 9
Write a program that encodes a word into Piglatin. To translate a word into a Piglatin word,
convert the word into uppercase and then place the first vowel of the original word as the start of
the new word along with the remaining alphabets. The alphabets present before the vowel being
shifted towards the end followed by “AY”.
Sample Input (1) : London, Sample Output (1) : ONDONLAY
Sample Input (2) : Olympics, Sample Output (2) : OLYMPICSAY

You might also like