0% found this document useful (0 votes)
29 views3 pages

Oops Revision Questions

Object is an instance of a class, while a class defines common attributes and behaviors of objects. Inheritance allows a child class to inherit attributes and behaviors from a parent class, while polymorphism allows child classes to override inherited methods. Parameters are inputs to methods/functions, while arguments are the actual values passed during a method call. An abstract class can have both abstract and non-abstract methods while an interface contains only abstract methods.

Uploaded by

Djibril Gathoni
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
29 views3 pages

Oops Revision Questions

Object is an instance of a class, while a class defines common attributes and behaviors of objects. Inheritance allows a child class to inherit attributes and behaviors from a parent class, while polymorphism allows child classes to override inherited methods. Parameters are inputs to methods/functions, while arguments are the actual values passed during a method call. An abstract class can have both abstract and non-abstract methods while an interface contains only abstract methods.

Uploaded by

Djibril Gathoni
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 3

%%%%%%%%%%%%%%%%%%%%

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.

d. Distinguish between parameters and arguments as used in Java.

b. Shape is an abstract class defined as shown below.


public abstract class Shape{
private String name;
public void setName(String name){
this.name = name;
}
public String getName(){
return name;
}
public abstract getArea();
public abstract getPerimeter();
}
(i). Rectangle is a Shape with attributes length and width in addition to the attributes of
Shape. Write the class definition for Rectangle.
(ii). Triangle is a Shape with attributes base and height in addition to the attributes of
Shape. Write the class definition for Triangle.
(iii). Write a main class ShapeTest to test your class in (i) and (ii) above. Create one
rectangle and one triangle objects and initialize all its attributes with values from the user.

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(){
}}

An interface is defined as shown below.


public interface Move{
public abstract String howToMove();
}
i. Write the getters and setters for the class Animal.
ii. A Frog and a Tortoise are all Animals with attributes color, height and length
respectively. Write the definitions of their classes. Use methods in (i) above to set
and return their name and date of birth. Your classes should implement the interface
Move to show how each of these animals move (Hint: Frog jumps and a Tortoise
crawls).
d. An array is declared as int marks[4][5];
i. How many elements can be stored in this array?
ii. What is the name of the first element in the array?
iii. What is the name of the tenth element in the array?
iv. What is the name of the last element in the array?
v. Using a nested for loop, write a Java code excerpt that displays all the elements of
the marks[5][5] array and their sum.(INITIALIZE USING random() CLASS

You might also like