VIT AP
Object Oriented Programming [CSE2005 - 030]
Marks: 50 Duration: 90 mins.
a
Answer all the questions.
1) Write a static method to convert a String into corresponding telephone number. (10)
This static method should use following rules for substituting letters or symbols with
digits.
If current character is an uppercase vowel, then replace with 2 and for lower vowel
replace with 3. Similarly, for uppercase consonants replace with 4 and for
lowercase consonants replace with 5. If any special symbol is seen, then it must be
replaced with its corresponding position (Consider that starting position is 1).
Example: String GoOd82# will be converted to 4325827
2) Create a class Order with three integer data members and three static methods: (10)
max, middle, and min. All three methods return maximum, middle, and minimum
values, respectively. Write a program with main class Test to test the class Order.
3) Create an abstract class GeometricFigure with one attribute x and two abstract (10)
methods area and setDimensions. Create each of the following classes.
a. Create Point as a subclass of GeometricFigure. Point has two attributes x and y,
both of type int.
b. Create Ellipse as a subclass of GeometricFigure. Ellipse has two attributes x and
y, both of type int for major and minor axes.
c. Create Circle as a subclass of Ellipse. No additional attribute required.
4) Create a class Factorial with one data member called num of type int and a method (10)
find() to return factorial of num. Create another class FactorialR from Factorial
which overrides method find() and this override method uses recursion to find and
returns factorial of data member of its super class.
5) Which is true about an anonymous inner class? (2.5)
It can extend
It can extend It can extend It can implement
exactly one class
exactly one class exactly one class multiple interfaces
and can
and implement or implement regardless of
implement
exactly one exactly one whether it also
multiple
interface. interface. extends a class.
interfaces.
6) class Foo (2.5)
{
class Bar{ }
}
class Test
{
public static void main (String [] args)
{
Foo f = new Foo();
/* Line 10: Missing statement ? */
}
}
which statement, inserted at line 10, creates an instance of Bar?
[Link] b = new [Link] b = [Link] Bar b = new Bar b = [Link]
[Link](); Bar(); [Link](); Bar();
7) What is the most restrictive access modifier that will allow members of one class to (2.5)
have access to members of another class in the same package?
public abstract protected default access
8) Which of the following is/are true about packages in Java? (2.5)
1) Every class is part of some package.
2) All classes in a file are part of the same package.
3) If no package is specified, the classes in the file
go into a special unnamed package
4) If no package is specified, a new package is created with
folder name of class and the class is put in this package.
Only 1, 2 and Only 1, 2 and
Only 4 Only 1 and 3
3 4
-----End-----