0% found this document useful (0 votes)
45 views28 pages

CS8392 Object Oriented Programming Exam

Uploaded by

Saravana Kumar
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)
45 views28 pages

CS8392 Object Oriented Programming Exam

Uploaded by

Saravana Kumar
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

Reg. No.

Question Paper Code : 40389

B.E./[Link]. DEGREE EXAMINATIONS, NOVEMBER/DECEMBER 2021.

Third/Fourth/Fifth Semester

Computer Science and Engineering

CS 8392 – OBJECT ORIENTED PROGRAMMING


(Common to: Computer and Communication Engineering /
Electrical and Electronics Engineering/ Electronics and Communication
Engineering/ Electronics and Instrumentation Engineering/
Electronics and Telecommunication Engineering/ Instrumentation and
Control Engineering/ Artificial Intelligence and Data Science/
Computer Science and Business System/ Information Technology)

(Regulations 2017)

Time : Three hours Maximum : 100 marks

Answer ALL questions.

PART A — (10  2 = 20 marks)

1. What is encapsulation?

2. Define polymorphism.

3. When a class must be declared as abstract?

4. Outline the use of extends keyword in Java with syntax.

5. What is chained exception?

6. How character streams are defined?

7. Name the two ways to create a thread in Java.

8. What is synchronization?

9. Name the two methods defined in [Link]. EventObject.

10. Draw the class hierarchy for Panel and Frame.


PART B — (5  13 = 65 marks)

11. (a) (i) Outline the arithmetic operators in Java. (6)


(ii) Name the four integer types in Java and outline the bitwise
operators that can be applied to the integer types.
(7)

Or
(b) (i) Outline the iteration statements in Java with syntax and example.
(9)
(ii) Outline the use of constructors and this keyword in Java. (4)

12. (a) (i) When a class hierarchy is created, in what order are the
constructors for the classes that make up the hierarchy called?
Outline with an example. (6)
(ii) Outline method overriding with an example.
(7)

Or
(b) (i) Write a note on interfaces and present the syntax for defining an
interface. (7)
(ii) Outline how interfaces are implemented in Java with an example.
(6)

13. (a) (i) "Java exception handling is managed via five keywords". Name the
five key words and present an outline of an exception-handling
block with syntax. (6)
(ii) Present an outline of Java's checked exceptions defined in java.
lang. (7)

Or
(b) What is InputStream? Present an outline of the methods defined by
InputStream. (13)

14. (a) (i) Outline the states a thread can be in and specify the rules that
determine when a context switch takes place.
(7)
(ii) Present an outline of the methods used by Java for interprocess
communication. (6)

Or
(b) (i) Why parameterized types are important? Outline Java generics
with an example. (7)
(ii) Outline parameter type bounds with an example. (6)

2 40389
15. (a) What is AWTEvent class? Name the main event classes in [Link]
and provide an outline of when they are generated.
(13)

Or
(b) (i) Outline the use of setSize(), getSize( ), setVisible() and setTitle()
methods when working with frame windows with their signature.
(8)
(ii) Name the four types of buttons swing defines and present an
outline of the same. (5)

PART C — (1  15 = 15 marks)

16. (a) Write a Java program to accept `n' names, store it in an array, sort the
names in alphabetic order and display the result. Use classes and
methods. (15)
Or
(b) Write a Java program to accept two square matrices, store them in an
array, add the matrices and display the result. Use classes and methods.
(15)

—————————

3 40389
Reg. No. :
*X10313*

Question Paper Code : X 10313


B.E./[Link]. Degree Examinations, november/decembeR 2020/
APRIL/MAY 2021
Third/Fourth/Fifth Semester
Computer Science and Engineering
cs 8392 – object oriented programming
(Common to : Computer and Communication Engineering/Electrical and
Electronics Engineering/Electronics and Communication Engineering/Electronics
and Instrumentation Engineering/Electronics and Telecommunication
Engineering/Instrumentation and Control Engineering/Information Technology)
(Regulations 2017)

Time : Three Hours Maximum : 100 Marks

Answer all questions


Part – A (10×2=20 Marks)
1. Define encapsulation in Java.
2. What is a constructor ?
3. Exemplify the use of super keyword.
4. What are the differences between classes and interfaces ?
5. What is the purpose of finally clause ? give example.
6. What are the uses of streams. What are the two types of streams ?
7. What is the need for synchronization ? How it can be implemented ?
8. How to create a single class, which automatically works with different types of
data ? Give example.
9. Write the sequence in which method calls takes place when an applet is terminated ?
Define those methods.
10. What are the two key features of swing ?

Part – B (5×13=65 Marks)


11. a) i) How Java changed the internet ? (9)
ii) If semicolons are needed at the end of each statement, why does the comment
line not end with a semicolon ? (4)
(OR)
b) What are the three categories of control statements used in Java ? Explain
each category with example. (13)
X 10313 -2- *X10313*

12. a) Write a Java program to calculate electricity bill using inheritance. The program
should get the inputs of watts per hour and unit rate.

Check your program for the following case :

Assume a consumer consumes 5000 watts per hour daily for one month. Calculate
the total energy bill of that consumer if per unit rate is 7 [1 unit = 1k Wh]. (13)
(OR)
b) What is interface ? With an example explain how to define and implement
interface. (13)

13. a) Write a short note on the following topics :

• Uncaught exceptions. (3)

• Difference between throw and throws. Give example for both. (5)

• Chained exceptions. Give example. (5)


(OR)
b) How to perform reading and writing files ? Explain with example. (13)

14. a) Discuss the different states of thread in detail. (13)


(OR)

b) i) What is the purpose of thread priorities ? What are the different thread
priorities that exist ? (5)

ii) What are bounded types ? Why it is used ? Give example. (8)

15. a) i) List any five different user interface components that can generate the
events. (5)

ii) Demonstrate any four mouse event handlers with example. (8)
(OR)
b) Describe how to work with graphics to display information within window. (13)
*X10313* -3- X 10313

Part – C (1×15=15 Marks)

16. a) Write an AWT GUI application (called AWT counter) as shown in the Figure 1.
Each time the “Count” button is clicked, the counter value shall increase by 1.

Figure 1
(OR)
b) Write an addressbook class that manages a collection of person object. An
addressbook will allow a person to add, delete, or search for a person object in
the address book.
• Add method : It should add a person object to the addressbook.
• Delete method: It should remove the specified person object from the book.
• Search method: It searches the address book for a specified person and returns
the list of persons matching the specified criteria. The search can be done either
by first name, last name or person id.

–––––––––––––

Common questions

Powered by AI

Encapsulation in Java is the practice of wrapping data (variables) and code acting on the data (methods) as a single unit or object. It helps maintain data integrity and security by restricting outside access to the internal state or variables, which only can be accessed through well-defined interfaces or methods. This promotes code security by preventing outside elements from altering the state of the object directly, reducing potential bugs and unintended side-effects .

Synchronization in Java is a mechanism that restricts multiple threads from accessing shared resources or critical sections simultaneously, ensuring thread safety and preventing race conditions. It is critical in scenarios where concurrent modifications to shared resources can lead to inconsistent data states. For example, synchronizing a method that updates a shared counter variable ensures that only one thread can modify it at a time, preventing data corruption when multiple threads attempt to increment the counter simultaneously .

Abstract classes in Java are classes that cannot be instantiated and are designed to be subclassed. They are significant when some base class functionalities need to be inherited by multiple subclasses, while also requiring additional subclass-specific implementations. Abstract classes can include both completed methods and abstract methods. They are preferable over interfaces when you want to provide a common base with shared code among different classes, such as sharing state or utility methods, which is not possible with interfaces as they do not hold fields .

Interfaces in Java facilitate polymorphism by allowing a class to implement multiple interfaces, thus defining multiple types of behavior that can be used polymorphically. Interfaces allow an object to be treated as an instance of any interface it implements, promoting flexibility in coding. However, interfaces lack the capability to store state or provide method implementations, which abstract classes can do. This means interfaces cannot offer shared code or fields, limiting code reuse to method contracts and requiring implementing classes to define all behavior, unlike abstract classes that can offer a mix of abstract methods and implemented methods .

Java Generics enable types (classes and interfaces) to be parameters when defining classes, interfaces, and methods, improving type safety by enforcing compile-time checks and reducing runtime errors. With generics, you can ensure that a collection contains only elements of a specific type, preventing errors like `ClassCastException`. For example, a parameterized class `Box<T>` allows you to specify the type of object to be stored using `Box<Integer>` or `Box<String>`, ensuring that only integers or strings are stored respectively, avoiding mismatched type operations .

Checked exceptions in Java are exceptions that must be either caught or declared in the method, whereas unchecked exceptions are not required to be handled or declared. Checked exceptions relate to conditions outside the control of program execution, such as IO errors, whereas unchecked exceptions are due to programming errors like illegal argument or null pointer references. This distinction influences how developers approach error handling, ensuring mandatory checking of recoverable exceptions with checked exceptions and permitting unchecked exceptions to be handled explicitly based on the application's requirements and robustness goals .

The `extends` keyword in Java is used to denote inheritance from a superclass, allowing a subclass to inherit fields and methods from it, establishing a class hierarchy. This keyword helps organize code into a well-structured framework by defining parent-child relationships between classes, facilitating method overriding and code reuse. For example, in a class hierarchy where a `Vehicle` class is extended by `Car` and `Bike`, both `Car` and `Bike` inherit common behaviors from `Vehicle` which they can further extend or override based on specific needs .

Using exceptions for error handling in Java provides clearer code structure and facilitates separation of error-handling logic from regular code flow compared to traditional error-checking methods. Exceptions enable a clean propagation of error states through method calls via throw mechanisms, reducing the need for constant error checks after each operation. This results in improved readability and maintainability of the code, as error handling is decoupled and programmed in a concentrated manner. Compared to traditional methods that mix error codes with normal logic, exceptions allow for centralized handling per exception type, simplifying debugging and supporting robust program execution .

In Java, a thread can be in one of several states: NEW, RUNNABLE, BLOCKED, WAITING, TIMED_WAITING, or TERMINATED. These states impact execution by determining the thread's ability to execute and its position within the thread scheduler. NEW indicates a thread that has not yet started; RUNNABLE signifies it is ready to run or currently executing; BLOCKED indicates it is waiting to enter a synchronized block/method; WAITING and TIMED_WAITING indicate it is waiting for another thread's action or specified time respectively; TERMINATED denotes completion of execution. Understanding these states helps in proper management and control of concurrency, especially when dealing with synchronization and context switching .

Polymorphism in Java allows objects to be treated as instances of their parent class, enhancing software flexibility by enabling a single method to operate on different types of objects. Method overriding exemplifies polymorphism where a subclass provides a specific implementation of a method declared in its superclass, allowing the same method name to behave differently based on the object type used at runtime. This approach increases software reusability and flexibility as new subclasses can override the method without altering the base class .

You might also like