Oops Revision Questions
Oops Revision Questions
a. Distinguish between the following terms as used in the object oriented programming
paradigm.
i. Object and Class.
ii. Inheritance and Polymorphism.
b. With examples, describe any THREE types of comments used in Java.
c. State THREE differences between an abstract class and an interface in Java.
d. Assume a = 4, b = 2 and c = 5, write the output of the following expressions.
i. 6 + b * ++a / (8 – b++)
ii. 9 – c-- / ++b * b + (17 % 5)
iii. 10 * -a + --c * a++ / 7 – a--
e. Rewrite the code snippet below using conditional operator
if (x > y)
number = 10;
else
number = 5;
f. Using loop construct of your choice, write a Java code that will produce the pattern shown
in the figure below.
g. Write a program that includes a try block and a catch clause which processes the
arithmetic exception generated by division-by-zero error.
h. Explain the difference between method overloading and method overriding.
h. Java programming language is platform independent. Discuss.
#################################
a. Explain the difference between method overriding and method overloading.
b. A class Person is defined as shown below:-
public class Person {
private String name;
private double height;
public Person(){
{
}
i. Write mutator method definitions that initializes the class variables.
ii. Write accessor method definitions that return values of class variables.
iii. Write the values of the variables as initialized by the constructor Person.
iv. Write a class definition for a class Student that inherits Person’s properties and
methods. In addition to Persons properties, the student has regNo and yearOfStudy.
Write getters and setters for the Student class. Use Person’s methods to initialize and
return the name, age and height properties of the student.
v. Write a class definition for a class GraduateStudent that inherits Student’s properties and
methods. In addition to students properties, the graduate student has researchTopic. Write
getters and setters for the GraduateStudennt class. Use Person’s and Student’s methods
to initialize and return the name, age, yearOfStudy, and regNo and height properties of
the graduate student.
c. Using flowcharts, explain the basic difference between while loop and the do…while
loop.
%%%%%%%%%%%%%%%%%%%%%%%%%%%
a. Explain the difference between public and private access modifies.
b. Evaluate the output following statement:
(17 < 4 ∗ 3 + 5) || (8 ∗ 2 == 4 ∗ 4) && ! (3 + 3 == 6)
c. Write the definition of a void method that takes as input a decimal number and outputs 3
times the value of the decimal number (up to two decimal places).
c. Class Animals is defined as shown below.
public class Animals{
private String name;
private Date dob;
public Animal(){
}}