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

Java Object-Oriented Programming Exam

This document contains instructions and questions for an exam on Object Oriented Programming in Java. It asks students to: 1) Explain the differences between objects and classes, and encapsulation and data abstraction. It also asks them to list and explain access control modifiers. 2) Design a Java program that calculates a customer's payment amount after applying a 5% discount if their order total is over 1000 Kshs. 3) Write a Java program that takes user input for values of x and y and outputs the value of a given expression involving those variables. So in summary, this exam tests students' understanding of core OO concepts in Java like classes, objects, encapsulation, and inheritance, as

Uploaded by

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

Java Object-Oriented Programming Exam

This document contains instructions and questions for an exam on Object Oriented Programming in Java. It asks students to: 1) Explain the differences between objects and classes, and encapsulation and data abstraction. It also asks them to list and explain access control modifiers. 2) Design a Java program that calculates a customer's payment amount after applying a 5% discount if their order total is over 1000 Kshs. 3) Write a Java program that takes user input for values of x and y and outputs the value of a given expression involving those variables. So in summary, this exam tests students' understanding of core OO concepts in Java like classes, objects, encapsulation, and inheritance, as

Uploaded by

BRIAN KAHARI
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd

W1-2-60-1-6

JOMO KENYATTA UNIVERSITY


OF
AGRICULTURE AND TECHNOLOGY
UNIVERSITY EXAMINATIONS 2014/2015
YEAR 2 SEMESTER II EXAMINATION FOR THE DEGREE OF BACHELOR OF SCIENCE IN
INFORMATION TECHNOLOGY
ICS 2104: OBJECT ORIENTED PROGRAMMING I (JAVA)
DATE: APRIL 2015 TIME: 2 HOURS

INSTRUCTIONS: Answer Question One and Any Other Two Questions

QUESTION ONE (30 MARKS)

a) State the main different between the following terms used in Object Oriented
Programming (4marks)
i) Object and classes
ii) Encapsulation and data abstraction
b) List and explain the main Access Control Modifiers in class declaration that are used in
Java programming (6marks)
c) Explain three reasons as to why Object oriented programming is gaining more
popularity as compared to procedural programing (3marks)
d) The value of a variable y depends on the value of variable x as shown below
(3marks)
X Y
1 0.1
2 0.2
Other value 0
Write down a Java switch structure for the probe
e) Design and write a Java program which accepts an amount of money entered in Kshs. If
the amount is greater or equal to 1000sh, a 5% discount is given to the customer. It
should also display the amount the customer has to pay (4marks)
f) Describe a constructor and explain any three rules for a valid construction in Java
programing (3marks)
g) Explain the part of the main method “public static void main (string []args)”
(4marks)


give output of a
6
h) Given a= X 5 +Y write a program that allow user to enter the value of x and y and
3
(4marks)

1|Page
QUESTION TWO (15 MARKS)

a) Explain the difference between method overriding and method overloading


(4marks)
b) State and explain four characteristics of Java programming which give advantage over
other high level programming languages (4marks)
c) Assume that every employee gets 20% house allowance. Assume also that those
earning at least 10,000 pay some tax at the rate of 10%. Design and write a Java code to
input the net salary. NB; Net salary=Basic salary +House allowance –tax
(2marks)
d) Explain the term Java development tool kit (JDK) and its main role in compiling
(2marks)
e) Explain the characteristics of objects in Java programming (3marks)

QUESTION THREE (15 MARKS)

a) With examples state the major differences between Java-stand-alone application and
Java applets (4marks)
b) Define the term array and write object oriented program that uses an array to store
four names and displays the names. (4marks)
c) Using switch statement write a Java program to display the day depending on the
choice entered by the user from the keyboard i.e 1 is Monday, 2 is Tuesday 3 is
Thursday………..7 is Sunday (6marks)
d) Given that a=20, b=5, c=9, what is the value of the following expressions
i) A>b and b>c
ii) A==b||a>=c
iii) With example of Java program explain the difference between static and
instance variables (4marks)

QUESTION FOUR (15 MARKS)

a) Give two differences between while….and do…..while loops (2marks)


i) Using a while loop, write a program to output all numbers divisiable by 2 in
descending order from 150 to 50 (4marks)
ii) Re-write the above program using do while loop. (3marks)
b) Write a Java program which allow the user to input four integers it then output the
maximum of the four integers (5marks)
c) Discuss the following object oriented concept use a simple example in each case
(6marks)
i) Encapsulation
ii) Polymorphism
iii) Inheritance

2|Page
QUESTION FIVE (20 MARKS)

a) Explain the difference steps used in developing a Java application (6marks)


b) Java library classes are organized into packages. Explain the use of the following
classes. (3marks)
i) [Link]
ii) [Link]
iii) [Link]
c) Write a Java program to input the price and quantity purchased of an item. The
program them computes the discount and the total amount to be paid. Assume a
discount of 6% (5marks)

3|Page

Common questions

Powered by AI

Objects are instances of classes that represent concrete items, whereas classes are blueprints or templates that define the structure and behaviors (methods) of objects. This distinction allows classes to define variables and methods while objects store actual data and represent instances of these classes.

The Java Development Kit (JDK) provides the tools necessary for developing Java applications, including the Java compiler (javac) to process Java source code into bytecode, and other utilities such as the Java Virtual Machine (JVM) essential for running these Java applications. The JDK thus provides an integral environment for both developing and executing Java programs.

Java is advantageous due to its platform independence, thanks to the Java Virtual Machine (JVM), extensive library support enhancing functionality without extra coding, built-in security features that limit unsafe operations, and strong memory management through automatic garbage collection. These characteristics make Java both powerful and reliable compared to many other programming languages.

Object-Oriented Programming (OOP) is gaining more popularity compared to procedural programming because it promotes code reusability through inheritance, provides a more natural modeling of real-world entities as objects, and enhances code maintainability by encapsulating data and behaviors. These benefits make OOP more suitable for managing complex software systems.

Method overriding occurs when a subclass provides a specific implementation for a method that is already defined in its superclass, focusing on polymorphism and run-time behavior changes. Method overloading, however, is when multiple methods in the same class share the same name but differ in the parameter list, promoting compile-time polymorphism. Overriding allows changing behavior, while overloading allows different functionalities with the same method name.

The 'while' loop evaluates the condition before executing the loop body, meaning the loop may not execute if the condition is false at the start. In contrast, the 'do-while' loop evaluates the condition after executing the loop body, ensuring the loop is executed at least once. This distinction makes 'do-while' useful when needing the body to run unconditionally once.

Encapsulation is the bundling of data with the methods that operate on that data, providing controlled access to the data via public interfaces. Data abstraction, on the other hand, is the concept of hiding the complex implementation details and showing only the essential features of an object. While encapsulation is about restricting access to certain components, data abstraction is about simplifying the interface.

Java applets are small programs that run within a web browser, requiring a browser with a Java plugin, and are used for interactive web applications, whereas stand-alone applications execute directly on a user's machine without a browser's aid, functioning more independently. Applets have more security restrictions due to their web-based nature, while stand-alone applications have fewer limitations and greater access to system resources.

In Java, the main access control modifiers are public, private, protected, and default (no modifier). 'Public' allows full access across all classes, 'private' restricts access to within the class itself, 'protected' permits access within the package and subclasses, and the default allows access only within the same package. These modifiers help in controlling the visibility of class members to enforce encapsulation and protect data integrity.

Static variables belong to the class rather than any object instance, meaning they are shared among all instances, with a single copy stored in memory. Instance variables, in contrast, are specific to each object, with individual copies generated upon the object's creation. Static variables provide utility across all objects, minimizing memory usage, whereas instance variables reflect individual object states.

You might also like