ANNA UNIVERSITY · REGULATION 2021
Important Questions
CS 3391 — OBJECT ORIENTED PROGRAMMING
Third Semester · Computer Science and Engineering
Prepared from 5 previous year question papers (Nov/Dec 2024, Apr/May 2024, Nov/Dec 2023, Apr/May 2023, Nov/Dec 2022). Every question was compared with the others of its unit; the ones asked more than once come first. "Most asked topics" shows in how many different exams a syllabus topic had a question.
UNIT 1Introduction to OOP and Java
Most asked topics: Object oriented programming paradigms (2/5) · Features of Object Oriented Programming (2/5) · Constructors (2/5) · Methods (2/5) · Data Types (1/5) · Operators (1/5)
Part A · 2 marks
- 1.How is encapsulation achieved in java?(2)
Asked in Nov/Dec 2024
- 2.State the type promotion rule in Java.(2)
Asked in Nov/Dec 2024
- 3.List the features of Object Oriented Programming.(2)
Asked in Apr/May 2024
- 4.Give an example for defining constant in Java.(2)
Asked in Apr/May 2024
- 5.What is an array? How multidimensional arrays are implemented in Java?(2)
Asked in Nov/Dec 2023
- 6.Name the access modifiers in Java.(2)
Asked in Nov/Dec 2023
Part B · 13 marks
- 1.(i) Outline the bitwise operators in Java that can be applied to the integer type. (ii) Outline while and do-while iteration statements in Java with its general form.(13)
Asked 2 times: Nov/Dec 2023, Apr/May 2023
Free sample · model answer from the exam kit
(i) Bitwise operators
Bitwise operators work on the individual bits of the integer types long, int, short, char and byte. Java stores integers in two's complement form, so the left-most bit is the sign bit.
- ~ Bitwise unary NOT: inverts every bit.
- & Bitwise AND: result bit is 1 only if both bits are 1.
- | Bitwise OR: result bit is 1 if either bit is 1.
- ^ Bitwise exclusive OR: result bit is 1 if the bits are different.
- << Left shift: shifts bits left, filling 0 on the right (each shift multiplies by 2).
- >> Right shift (signed): shifts bits right, copying the sign bit into the left (each shift divides by 2).
- >>> Unsigned right shift: shifts bits right, always filling 0 on the left.
- Compound forms: &=, |=, ^=, <<=, >>=, >>>=.
Worked example with a = 12 (binary 1100) and b = 10 (binary 1010):
- a & b = 1000 = 8
- a | b = 1110 = 14
- a ^ b = 0110 = 6
- ~a = -13 (all 32 bits flipped; ~x = -x - 1)
- a << 2 = 110000 = 48
- a >> 2 = 0011 = 3
- -12 >> 2 = -3 (sign bit copied)
- -12 >>> 28 = 15 (-12 is 0xFFFFFFF4; the top four 1-bits move to the bottom and zeros fill the left)
class BitDemo { public static void main(String[] args) { int a = 12, b = 10; System.out.println("a & b = " + (a & b)); // 8 System.out.println("a | b = " + (a | b)); // 14 System.out.println("a ^ b = " + (a ^ b)); // 6 System.out.println("~a = " + (~a)); // -13 System.out.println("a << 2 = " + (a << 2)); // 48 System.out.println("a >> 2 = " + (a >> 2)); // 3 System.out.println("-12 >>> 28 = " + (-12 >>> 28)); // 15 } }(ii) while and do-while statements
The while loop is an entry-controlled loop: the condition is tested before the body runs, so the body may execute zero times.
General form:
while (condition) { // body of loop }Draw: Flowchart of while: Start -> diamond "condition?" -> True -> "body" -> back to diamond; False -> exit.
Example:
int n = 1; while (n <= 3) { System.out.println("n = " + n); // prints 1, 2, 3 n++; }The do-while loop is an exit-controlled loop: the body runs first and the condition is tested at the end, so the body always executes at least once. Note the semicolon after the condition.
General form:
do { // body of loop } while (condition);Draw: Flowchart of do-while: Start -> "body" -> diamond "condition?" -> True -> back to "body"; False -> exit.
Example:
int n = 5; do { System.out.println("n = " + n); // prints 5 once n++; } while (n <= 3);Here the condition 6 <= 3 is false, yet "n = 5" is printed once. A while loop with the same data would print nothing.
Difference in short:
- while tests first (entry-controlled); do-while tests last (exit-controlled).
- while may run 0 times; do-while runs at least once.
- do-while is useful for menu-driven programs where the menu must be shown at least once.
The CS3391 exam kit has model answers like this for 32 of these questions.
- 2.Explain in detail about Java's Selection statements with example.(13)
Asked in Nov/Dec 2024
- 3.What is a class? Write the general form of a class and explain how to declare an object and add a method to class that takes parameter?(13)
Asked in Nov/Dec 2024
- 4.Discuss the various access specifiers in Java.(13)
Asked in Apr/May 2024
UNIT 2Inheritance, Packages and Interfaces
Most asked topics: Overloading Methods (3/5) · Method Overriding (3/5) · Super keyword (2/5) · Inheritance: Basics (1/5) · Dynamic Method Dispatch (1/5) · Abstract Classes (1/5)
Part A · 2 marks
- 1.What is method overloading?(2)
Asked 2 times: Nov/Dec 2024, Nov/Dec 2022
- 2.State the two general forms of using super keyword.(2)
Asked in Nov/Dec 2024
- 3.Mention the use of constructor overloading.(2)
Asked in Apr/May 2024
- 4.Illustrate method overriding with an example.(2)
Asked in Apr/May 2024
- 5.Define inheritance.(2)
Asked in Nov/Dec 2023
- 6.How can a subclass can call a constructor defined by its superclass?(2)
Asked in Nov/Dec 2023
Part B · 13 marks
- 1.Explain about the Dynamic Method Dispatch in Java with example.(13)
Asked in Nov/Dec 2024
- 2.Discuss in detail about the methods available in object class.(13)
Asked in Nov/Dec 2024
- 3.With an example explain the use of Abstract classes in Java.(13)
Asked in Apr/May 2024
- 4.What is user defined package? How to create and import a user defined package? Explain with example.(13)
Asked in Apr/May 2024
UNIT 3Exception Handling and Multithreading
Most asked topics: Java's Built-in Exceptions (1/5) · User defined Exception (1/5) · Synchronization (1/5) · Multithreading (1/5) · Wrappers (1/5)
Part A · 2 marks
- 1.Define thread priority.(2)
Asked in Nov/Dec 2024
- 2.Why is autoboxing used?(2)
Asked in Nov/Dec 2024
- 3.Why to handle exceptions?(2)
Asked in Apr/May 2024
- 4.What is thread priority? How it can be set for a thread?(2)
Asked in Apr/May 2024
- 5.Outline the difference between unchecked exceptions and checked exceptions.(2)
Asked in Nov/Dec 2023
- 6.Name the methods used by Java for interprocess communication to avoid polling.(2)
Asked in Nov/Dec 2023
Part B · 13 marks
- 1.Explain how the exception handling in java is handled.(13)
Asked 2 times: Nov/Dec 2024, Nov/Dec 2023
- 2.Discuss in detail about java thread model.(13)
Asked in Nov/Dec 2024
- 3.Discuss about user defined exceptions in Java. Give suitable example.(13)
Asked in Apr/May 2024
- 4.How thread synchronization is managed in java. Write example code.(13)
Asked in Apr/May 2024
UNIT 4I/O, Generics, String Handling
Most asked topics: methods and String Buffer Class (3/5) · I/O Basics (1/5) · Reading and Writing Console I/O (1/5) · Generics: Generic Programming (1/5) · Generic classes (1/5) · Generic Methods (1/5)
Part A · 2 marks
- 1.Write any two forms of PrintStream constructors.(2)
Asked in Nov/Dec 2024
- 2.State the functionality of BufferedInputStream( ).(2)
Asked in Nov/Dec 2024
- 3.Write any four methods associated with basic string class.(2)
Asked in Apr/May 2024
- 4.What is a String Buffer Class?(2)
Asked in Apr/May 2024
- 5.What are streams?(2)
Asked in Nov/Dec 2023
- 6.Why parameterized types are important?(2)
Asked in Nov/Dec 2023
Part B · 13 marks
- 1.Write a Java program that read and write the data from console.(13)
Asked 2 times: Nov/Dec 2024, Apr/May 2024
- 2.Discuss the four different ways to extract a character from string object.(13)
Asked in Nov/Dec 2024
- 3.Discuss about Generic classes and Generic methods in Java.(13)
Asked in Apr/May 2024
- 4.(i) Outline reading console input and writing console output in Java. (ii) Present an outline of FileInputStream and FileOutputStream classes.(13)
Asked in Nov/Dec 2023
UNIT 5JavaFX Event Handling, Controls and Components
Most asked topics: Layouts (2/5) · HBox and VBox (2/5) · Handling Key and Mouse Events (1/5) · Controls: Checkbox (1/5)
Part A · 2 marks
- 1.Write a note on HBox and VBox.(2)
Asked 2 times: Nov/Dec 2023, Nov/Dec 2022
- 2.How CardLayout class is unique among the other Layout managers?(2)
Asked in Nov/Dec 2024
- 3.What is an Inner class?(2)
Asked in Nov/Dec 2024
- 4.Why JAVAFX is preferred for building Internet applications?(2)
Asked in Apr/May 2024
- 5.Write the constructors of HBox class.(2)
Asked in Apr/May 2024
- 6.What is JavaFX?(2)
Asked in Nov/Dec 2023
Part B · 13 marks
- 1.Discuss in detail about the delegation event model approach for event handling.(13)
Asked in Nov/Dec 2024
- 2.Explain in detail about the class hierarchy for panel and frame.(13)
Asked in Nov/Dec 2024
- 3.With an example code explain how the key events are handled using JAVAFX.(13)
Asked in Apr/May 2024
- 4.Write a Java program to illustrate the use of JAVAFX checkbox and choice box controls.(13)
Asked in Apr/May 2024
PART CAny unit
Part C · 15 marks
- 1.Explain the concept of threads in Java. Write a Java program that creates three threads. Each thread should decrement its counter variable for every 10 seconds.(15)
Asked in Nov/Dec 2024
- 2.Develop a java application for a simple calculator that performs basic arithmetic operations (addition, subtraction, multiplication and division). How do you handle the 'division by zero' scenario gracefully? Include your suggestion in the implementation.(15)
Asked in Nov/Dec 2024
- 3.Design a class called Ship that has the following members: - Name of the ship-string - Year-the year of the ship built in integer - A constructor, get and set methods - to String that displays the name of the ship and year. Extend a class CruiseShip from Ship with the following members: - Maximum number of passengers - integer - A constructor, get and set methods - To String method that overrides base class to display the name of the ship and number of passengers. …(15)
Asked in Apr/May 2024
- 4.A and B are any two players in a game which progresses by making alternate moves by the players. Assume the odd moves are played by the player A and the even moves are played by the player B. Define a class for generating the player move which implements runnable interface and ensures that the player is operated with lock. Implement using thread pool so that A and B will get only the alternate moves. The players can stop after making a total of 100 moves.(15)
Asked in Apr/May 2024
- 5.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)
Asked in Nov/Dec 2023
- 6.Write a java program with nested try statements that raises divide by zero exception and out of bound exception, if the program contains a statement with division operator and a divisor as a command line argument.(15)
Asked in Apr/May 2023