0% found this document useful (0 votes)
3 views25 pages

OOP Java Study Guide

The document provides comprehensive notes on Object-Oriented Programming (OOP) using Java, covering key concepts, features, and components across nine chapters. It includes topics such as Java basics, flow control, OOP principles, exception handling, GUI programming with JavaFX, JDBC for database connectivity, and networking. Additionally, it features multiple-choice questions to test understanding of the material presented.

Uploaded by

Tabiri Bright
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)
3 views25 pages

OOP Java Study Guide

The document provides comprehensive notes on Object-Oriented Programming (OOP) using Java, covering key concepts, features, and components across nine chapters. It includes topics such as Java basics, flow control, OOP principles, exception handling, GUI programming with JavaFX, JDBC for database connectivity, and networking. Additionally, it features multiple-choice questions to test understanding of the material presented.

Uploaded by

Tabiri Bright
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

OOP Using Java

Object-Oriented Programming — All 9 Chapters Notes, MCQ, True/False, Fill-in, Matching —


100 Questions

TBUDWORLD • ITE Group 4 • AAMUSTED • Dr. George Asante

Ch Title Topics

Jav History, JVM, WORA, Data


aB types, Editions
asi
cs

Ele Variables, Operators, Strings,


me Arrays, Scanner
nts
of J
ava
Pro
gra
m
min
g

Flo if-else, switch, for, while,


w do-while, break, continue
Co
ntr
ol

Intr Classes, Objects, Constructors,


od Access Modifiers, Static
ucti
on
to
OO
P

Pill Encapsulation, Inheritance,


ars Polymorphism, Abstraction,
of Interfaces
OO
P

OOP Using Java • Dr. George Asante • TBUDWORLD • Page 1


Ex try-catch-finally, throw/throws,
cep Checked/Unchecked, Custom
tion
Ha
ndli
ng

Jav Stage, Scene, Layouts,


aG Controls, FXML, Events
UI (
Jav
aF
X)

Jav Connection,
aD PreparedStatement, CRUD,
ata ResultSet
bas
e(
JD
BC
)

Net Sockets, TCP/UDP,


wor ServerSocket, InetAddress, URL
kin
g in
Jav
a

OOP Using Java • Dr. George Asante • TBUDWORLD • Page 2


CHAPTER NOTES

All 9 Chapters — Java OOP

Chapter 1 — Java Basics

What is Java?
Java is a high-level, object-oriented, platform-independent programming language developed by James
Gosling at Sun Microsystems in 1995. Originally called Oak, then Green.

Key Features
• Platform Independent — Write Once, Run Anywhere (WORA). Compiles to bytecode, runs on JVM.
• Object-Oriented — Everything modelled as objects.
• Simple — Removed C++ complexities (no pointers, operator overloading).
• Secure — No explicit pointers; runs in JVM sandbox.
• Robust — Strong memory management, exception handling, garbage collection.
• Multithreaded — Multiple tasks simultaneously.

Java Execution Process

Source Code (.java) → javac Compiler → Bytecode (.class) → JVM → Machine Code

Java Editions

Edition Full Name Used For

Java SE Standard Edition Core language, general-purpose


apps

Java EE Enterprise Edition Web apps, servers, enterprise


systems

Java ME Micro Edition Mobile, embedded, small devices

JavaFX JavaFX Rich GUI internet applications

First Java Program

public class Hello { public static void main(String[] args) { [Link]("Hello,


World!"); } }

★ Key Points

• Java is case-sensitive

• Every Java program needs a main() method

• Class name must match filename (.java)

OOP Using Java • Dr. George Asante • TBUDWORLD • Page 3


• JDK = JRE + Dev Tools | JRE = JVM + Libraries

Chapter 2 — Elements of Java Programming

Variables and Data Types

int age = 20; // integer double gpa = 3.75; // decimal String name = "Thomas"; // text boolean
active = true; // true/false final double PI = 3.14159; // constant (cannot change)

Operators

Type Operators Example

Arithmetic +-*/% 10 % 3 = 1

Relational == != > < >= <= age > 18

Logical && || ! (a>0) && (b>0)

Ternary condition ? t : f x>0 ? "pos" : "neg"

Increment ++ -- i++, --j

Type Casting

// Widening (automatic): smaller → larger int x = 10; double d = x; // OK // Narrowing


(explicit): larger → smaller double pi = 3.14; int n = (int) pi; // n = 3

Arrays

int[] marks = {85, 90, 78}; int[] scores = new int[5]; // array of 5
[Link](marks[0]); // 85 [Link]([Link]); // 3 int[][] matrix = new
int[3][3]; // 2D array

Chapter 3 — Flow Control

if-else

if (score >= 80) { [Link]("Grade A"); } else if (score >= 70) {


[Link]("Grade B"); } else { [Link]("Below B"); }

Loops — for, while, do-while

// FOR loop for (int i = 0; i < 5; i++) { [Link](i); } // WHILE loop — checks BEFORE
executing while (i < 5) { [Link](i++); } // DO-WHILE — executes AT LEAST ONCE, checks
AFTER do { [Link](j++); } while (j < 5); // Enhanced FOR (for-each) for (int x : arr)
{ [Link](x); }

★ break vs continue

break — exits the loop entirely

continue — skips current iteration, goes to next

OOP Using Java • Dr. George Asante • TBUDWORLD • Page 4


Chapter 4 — Introduction to OOP

Class and Object

public class Student { String name; // field/attribute int age; // Constructor public
Student(String name, int age) { [Link] = name; // 'this' = current object [Link] = age; }
public void display() { [Link](name + ", Age: " + age); } } // Creating an object:
Student s1 = new Student("Thomas", 20); [Link](); // Thomas, Age: 20

Access Modifiers

Modifier Access Scope

public Everywhere (any class)

private Only within the same class

protected Same class + subclasses + same package

default (none) Same package only

Static Members

static int count = 0; // shared by ALL objects public static void show() { } // no object needed
[Link](); // called on class, not instance

Chapter 5 — Pillars of OOP (APIE)


★ Remember APIE

Abstraction | Polymorphism | Inheritance | Encapsulation

1. Encapsulation — Data Hiding


Wrap data (fields) and methods, restricting access with private fields + public getters/setters.

public class BankAccount { private double balance; // hidden public double getBalance() { return
balance; } // getter public void deposit(double amt) { if(amt>0) balance+=amt; } // setter }

2. Inheritance — IS-A Relationship


A child class extends a parent class. Java supports SINGLE inheritance only.

class Animal { public void eat() { [Link]("Eats"); } } class Dog extends Animal {
public void bark() { [Link]("Barks"); } } Dog d = new Dog(); [Link](); // inherited
from Animal [Link](); // Dog's own method

3. Polymorphism — Many Forms

Type Keyword When Example

Overloading Same class Compile-time add(int,int) and


add(double,double)

Overriding @Override Runtime Child redefines parent's


method

OOP Using Java • Dr. George Asante • TBUDWORLD • Page 5


4. Abstraction — Hide Complexity

abstract class Shape { abstract double area(); // subclass MUST implement void display() {
[Link]("Shape"); } // concrete method } interface Drawable { void draw(); // public
abstract by default } class Circle extends Shape implements Drawable { double r; public double
area() { return [Link] * r * r; } public void draw() { [Link]("Drawing circle"); } }

■ Abstract class can have constructors and concrete methods. Interface cannot. A class can implement MULTIPLE
interfaces but extend only ONE class.

Chapter 6 — Exception Handling in Java

Exception Hierarchy

Throwable ■■■ Error (do NOT catch: OutOfMemoryError, StackOverflowError) ■■■ Exception ■■■
Checked (MUST handle: IOException, FileNotFoundException) ■■■ Unchecked (optional:
NullPointerException, ArithmeticException, ArrayIndexOutOfBoundsException,
NumberFormatException)

try-catch-finally

try { int result = 10 / 0; // throws ArithmeticException } catch (ArithmeticException e) {


[Link]("Error: " + [Link]()); } finally { [Link]("Always
executes!"); // cleanup }

throw vs throws

// throw — manually throw an exception if (age < 0) throw new IllegalArgumentException("Invalid


age!"); // throws — declare method may throw checked exception public void readFile(String path)
throws IOException { }

★ Key Rules

• finally ALWAYS executes (even after return)

• Catch specific exceptions BEFORE general ones

• Checked exceptions must be caught or declared with throws

Chapter 7 — Java GUI Programming using JavaFX

JavaFX Application Structure

public class MyApp extends Application { @Override public void start(Stage stage) { Button btn =
new Button("Click!"); VBox root = new VBox(btn); Scene scene = new Scene(root, 300, 200);
[Link]("My App"); [Link](scene); [Link](); } public static void main(String[]
args) { launch(args); } }

Key JavaFX Components

Component Description

Stage Main application window (top-level container)

OOP Using Java • Dr. George Asante • TBUDWORLD • Page 6


Scene Content area placed inside Stage

VBox Arranges nodes vertically

HBox Arranges nodes horizontally

GridPane Table-like grid layout

FXML XML file for defining UI layout

Button/Label/TextField Common UI controls

Chapter 8 — Java Database Programming (JDBC)

The 5 JDBC Steps

// 1. Import import [Link].*; // 2. Load Driver [Link]("[Link]"); //


3. Connect Connection conn = [Link](url, user, pass); // 4. Execute
Statement stmt = [Link](); ResultSet rs = [Link]("SELECT * FROM
students"); // 5. Process & Close while([Link]()) { [Link]([Link]("name")); }
[Link]();

Statements & CRUD

Type Purpose

Statement Static SQL queries

PreparedStatement Parameterized queries, prevents SQL injection

executeQuery() For SELECT — returns ResultSet

executeUpdate() For INSERT/UPDATE/DELETE — returns rows affected

Chapter 9 — Networking Programming using Java

Java Networking ([Link] package)

// SERVER ServerSocket server = new ServerSocket(5000); Socket client = [Link](); // waits


for connection // CLIENT Socket socket = new Socket("localhost", 5000); PrintWriter pw = new
PrintWriter([Link](), true); [Link]("Hello from client!");

Protocol Type Use Case

TCP Connection-oriented, reliable Chat, file transfer, web

UDP Connectionless, fast Video streaming, DNS, gaming

OOP Using Java • Dr. George Asante • TBUDWORLD • Page 7


MULTIPLE CHOICE QUESTIONS

40 Questions — All 9 Chapters

Q1.
Java was developed by:
A. Bill Gates
B. James Gosling
C. Dennis Ritchie
D. Bjarne Stroustrup
✓ Answer: B. James Gosling
Explanation: James Gosling at Sun Microsystems, 1995.

Q2.
What does JVM stand for?
A. Java Virtual Module
B. Java Variable Memory
C. Java Virtual Machine
D. Java Version Manager
✓ Answer: C. Java Virtual Machine
Explanation: JVM = Java Virtual Machine — executes Java bytecode on any platform.

Q3.
Java's 'Write Once, Run Anywhere' feature is called:
A. Portability
B. Platform Independence
C. Robustness
D. Multithreading
✓ Answer: B. Platform Independence
Explanation: Platform independence: bytecode runs on any OS with a JVM.

Q4.
Which file extension does compiled Java bytecode have?
A. .java
B. .exe
C. .class
D. .jar
✓ Answer: C. .class
Explanation: javac compiles .java → .class (bytecode) files.

OOP Using Java • Dr. George Asante • TBUDWORLD • Page 8


Q5.
Which Java edition is for mobile and embedded devices?
A. Java SE
B. Java EE
C. Java ME
D. JavaFX
✓ Answer: C. Java ME
Explanation: Java ME (Micro Edition) targets small/mobile devices.

Q6.
Which keyword declares a constant in Java?
A. const
B. static
C. final
D. constant
✓ Answer: C. final
Explanation: 'final' makes a variable's value unchangeable.

Q7.
Output of: [Link](10 % 3);
A. 3
B. 1
C. 0
D. 3.33
✓ Answer: B. 1
Explanation: 10 % 3 = 1 (remainder of 10 ÷ 3).

Q8.
Which is NOT a primitive type in Java?
A. int
B. boolean
C. String
D. double
✓ Answer: C. String
Explanation: String is a reference type (class), not primitive.

Q9.
"Java".length() returns:
A. 3
B. 4
C. 5
D. 6
✓ Answer: B. 4
Explanation: J-a-v-a = 4 characters.

OOP Using Java • Dr. George Asante • TBUDWORLD • Page 9


Q10.
Larger type to smaller type conversion is called:
A. Widening
B. Casting
C. Narrowing
D. Promotion
✓ Answer: C. Narrowing
Explanation: Narrowing (explicit cast) converts from larger to smaller type.

Q11.
Which loop executes at least once?
A. for
B. while
C. do-while
D. enhanced for
✓ Answer: C. do-while
Explanation: do-while checks condition AFTER executing body.

Q12.
'break' inside a loop:
A. Pauses loop
B. Skips iteration
C. Exits loop completely
D. Goes to next method
✓ Answer: C. Exits loop completely
Explanation: break terminates the loop immediately.

Q13.
'continue' inside a loop:
A. Exits loop
B. Returns value
C. Skips current iteration
D. Stops program
✓ Answer: C. Skips current iteration
Explanation: continue skips rest of current iteration, goes to next.

Q14.
for(int i=0; i<5; i++) executes how many times?
A. 4
B. 5
C. 6
D. 0
✓ Answer: B. 5
Explanation: i = 0,1,2,3,4 → executes 5 times.

OOP Using Java • Dr. George Asante • TBUDWORLD • Page 10


Q15.
Keyword to create an object in Java:
A. create
B. object
C. new
D. make
✓ Answer: C. new
Explanation: 'new' allocates memory and creates an instance.

Q16.
'this' keyword refers to:
A. Parent class
B. Current object
C. New object
D. Static member
✓ Answer: B. Current object
Explanation: 'this' = current instance of the class.

Q17.
Most restrictive access modifier:
A. public
B. protected
C. private
D. default
✓ Answer: C. private
Explanation: private — accessible only within the same class.

Q18.
A constructor:
A. Destroys objects
B. Initializes objects
C. Returns a value
D. Is always static
✓ Answer: B. Initializes objects
Explanation: Constructor has class name, no return type, initializes object.

Q19.
Static methods can be called:
A. Only on objects
B. Without an object
C. Only inside class
D. After super()
✓ Answer: B. Without an object
Explanation: Static members called on class: [Link]().

OOP Using Java • Dr. George Asante • TBUDWORLD • Page 11


Q20.
OOP pillar that hides data with private fields + getters/setters:
A. Inheritance
B. Polymorphism
C. Encapsulation
D. Abstraction
✓ Answer: C. Encapsulation
Explanation: Encapsulation = data hiding through access control.

Q21.
Inheritance in Java uses keyword:
A. implements
B. extends
C. inherits
D. uses
✓ Answer: B. extends
Explanation: 'extends' establishes class inheritance.

Q22.
Same method name, different params in same class:
A. Overriding
B. Overloading
C. Polymorphism
D. Abstraction
✓ Answer: B. Overloading
Explanation: Method Overloading = compile-time polymorphism.

Q23.
A class that cannot be instantiated:
A. Final class
B. Static class
C. Abstract class
D. Interface
✓ Answer: C. Abstract class
Explanation: Abstract class cannot use 'new'. Must be subclassed.

Q24.
Java class can extend how many classes?
A. Unlimited
B. 2
C. 1
D. Depends on JDK
✓ Answer: C. 1
Explanation: Java: single inheritance only — extends ONE class.

OOP Using Java • Dr. George Asante • TBUDWORLD • Page 12


Q25.
Annotation for method overriding:
A. @Static
B. @Override
C. @Inherited
D. @Super
✓ Answer: B. @Override
Explanation: @Override tells compiler to verify the override is correct.

Q26.
Interface uses which keyword to be used by a class?
A. extends
B. inherits
C. implements
D. uses
✓ Answer: C. implements
Explanation: A class 'implements' an interface.

Q27.
Block that ALWAYS executes in exception handling:
A. try
B. catch
C. finally
D. throw
✓ Answer: C. finally
Explanation: finally always executes — even with exceptions or returns.

Q28.
NullPointerException is which type?
A. Checked
B. Unchecked
C. Error
D. Throwable
✓ Answer: B. Unchecked
Explanation: NullPointerException = unchecked (RuntimeException).

Q29.
Keyword to manually throw an exception:
A. throws
B. catch
C. throw
D. raise
✓ Answer: C. throw
Explanation: 'throw' creates and throws an exception. 'throws' declares it.

OOP Using Java • Dr. George Asante • TBUDWORLD • Page 13


Q30.
Main window in JavaFX:
A. Scene
B. Node
C. Stage
D. Frame
✓ Answer: C. Stage
Explanation: Stage = top-level application window in JavaFX.

Q31.
JavaFX layout for vertical arrangement:
A. HBox
B. GridPane
C. VBox
D. BorderPane
✓ Answer: C. VBox
Explanation: VBox arranges children in a vertical column.

Q32.
FXML is used for:
A. Database
B. UI layout in XML
C. Business logic
D. Networking
✓ Answer: B. UI layout in XML
Explanation: FXML defines JavaFX UI in XML, separate from Java logic.

Q33.
JDBC stands for:
A. Java Database Connection
B. Java Database Connectivity
C. Java Dynamic Base
D. Java Data Bridge
✓ Answer: B. Java Database Connectivity
Explanation: JDBC = Java Database Connectivity.

Q34.
JDBC method for SELECT queries:
A. executeUpdate()
B. execute()
C. executeQuery()
D. executeSelect()
✓ Answer: C. executeQuery()
Explanation: executeQuery() returns ResultSet for SELECT operations.

OOP Using Java • Dr. George Asante • TBUDWORLD • Page 14


Q35.
PreparedStatement prevents:
A. Compile errors
B. SQL injection
C. Network errors
D. Memory leaks
✓ Answer: B. SQL injection
Explanation: Parameterized queries prevent SQL injection attacks.

Q36.
Java networking package:
A. [Link]
B. [Link]
C. [Link]
D. [Link]
✓ Answer: B. [Link]
Explanation: [Link] contains Socket, ServerSocket, URL, InetAddress.

Q37.
Connection-oriented, reliable protocol:
A. UDP
B. FTP
C. TCP
D. HTTP
✓ Answer: C. TCP
Explanation: TCP ensures reliable, ordered delivery. UDP is faster but unreliable.

Q38.
Class for server listening for connections:
A. Socket
B. DatagramSocket
C. ServerSocket
D. NetSocket
✓ Answer: C. ServerSocket
Explanation: ServerSocket listens on a port; accept() waits for clients.

Q39.
Widening conversion is:
A. Explicit
B. Automatic
C. Manual
D. Unsafe
✓ Answer: B. Automatic
Explanation: Widening (smaller to larger) is automatic — no explicit cast needed.

OOP Using Java • Dr. George Asante • TBUDWORLD • Page 15


Q40.
Which is true about do-while vs while?
A. Same behavior
B. do-while may not execute
C. while executes at least once
D. do-while executes at least once
✓ Answer: D. do-while executes at least once
Explanation: do-while always executes at least once; while may not execute at all.

OOP Using Java • Dr. George Asante • TBUDWORLD • Page 16


TRUE / FALSE QUESTIONS

25 Questions — OOP Using Java

T/F Q1.
Java is a platform-dependent programming language.
Answer: FALSE ✓
Explanation: Java is platform-INDEPENDENT. WORA — bytecode runs on any JVM.

T/F Q2.
The JVM converts Java source code to bytecode.
Answer: FALSE ✓
Explanation: The COMPILER (javac) does this. JVM executes the bytecode.

T/F Q3.
Java supports multiple inheritance through classes.
Answer: FALSE ✓
Explanation: Java: single inheritance for classes. Multiple interfaces allowed.

T/F Q4.
A constructor must have the same name as the class.
Answer: TRUE ✓
Explanation: Constructor name = class name, no return type, called with 'new'.

T/F Q5.
The 'final' keyword prevents a class from being subclassed.
Answer: TRUE ✓
Explanation: final class cannot be extended. final variable = constant.

T/F Q6.
private members are inherited by child classes.
Answer: FALSE ✓
Explanation: Private members are NOT inherited. Only public and protected are.

T/F Q7.
Method overloading is runtime polymorphism.
Answer: FALSE ✓
Explanation: Overloading = compile-time. Overriding = runtime polymorphism.

OOP Using Java • Dr. George Asante • TBUDWORLD • Page 17


T/F Q8.
An abstract class can have both abstract and concrete methods.
Answer: TRUE ✓
Explanation: Abstract classes mix abstract (no body) and concrete (with body) methods.

T/F Q9.
A class can implement multiple interfaces in Java.
Answer: TRUE ✓
Explanation: Multiple interface implementation is allowed — Java's way of multiple inheritance.

T/F Q10.
'finally' only executes when no exception is thrown.
Answer: FALSE ✓
Explanation: finally ALWAYS executes regardless of exceptions.

T/F Q11.
NullPointerException must be declared with throws.
Answer: FALSE ✓
Explanation: NullPointerException is unchecked. Only checked exceptions need throws.

T/F Q12.
PreparedStatement prevents SQL injection attacks.
Answer: TRUE ✓
Explanation: Parameterized queries (?) prevent SQL injection.

T/F Q13.
executeQuery() is used for INSERT, UPDATE, DELETE.
Answer: FALSE ✓
Explanation: executeUpdate() for DML. executeQuery() for SELECT.

T/F Q14.
In JavaFX, a Scene is placed inside a Stage.
Answer: TRUE ✓
Explanation: Stage (window) contains Scene which contains UI nodes.

T/F Q15.
'super' accesses the current class's methods.
Answer: FALSE ✓
Explanation: 'super' = parent class. 'this' = current class.

T/F Q16.
Java's garbage collector automatically manages memory.
Answer: TRUE ✓
Explanation: GC frees memory from unreferenced objects automatically.

OOP Using Java • Dr. George Asante • TBUDWORLD • Page 18


T/F Q17.
TCP is faster than UDP.
Answer: FALSE ✓
Explanation: UDP is faster — no connection setup or delivery guarantees.

T/F Q18.
[Link]() blocks until a client connects.
Answer: TRUE ✓
Explanation: accept() is blocking — server waits for client.

T/F Q19.
The String class in Java is mutable.
Answer: FALSE ✓
Explanation: String is IMMUTABLE. Use StringBuilder for mutable strings.

T/F Q20.
Static variable belongs to the class, not individual objects.
Answer: TRUE ✓
Explanation: Static members are shared across all instances of the class.

T/F Q21.
do-while checks condition before executing.
Answer: FALSE ✓
Explanation: do-while checks AFTER — guarantees at least one execution.

T/F Q22.
Encapsulation uses private fields with public getters/setters.
Answer: TRUE ✓
Explanation: This is the core pattern of encapsulation for data protection.

T/F Q23.
An interface can have a constructor.
Answer: FALSE ✓
Explanation: Interfaces have no constructors and cannot be instantiated.

T/F Q24.
'break' in switch prevents fall-through.
Answer: TRUE ✓
Explanation: Without break, execution falls into the next case.

T/F Q25.
Java source files must have .java extension.
Answer: TRUE ✓
Explanation: .java = source, .class = compiled bytecode.

OOP Using Java • Dr. George Asante • TBUDWORLD • Page 19


FILL-IN-THE-BLANK

20 Questions — OOP Using Java

Fill-in Q1.
The four pillars of OOP are Encapsulation, Abstraction, Polymorphism, and ___________.
Answer: Inheritance

Fill-in Q2.
The keyword used in Java to inherit from a parent class is ___________.
Answer: extends

Fill-in Q3.
A ___________ is a special method with the same name as its class and no return type.
Answer: constructor

Fill-in Q4.
The ___________ keyword refers to the current object inside a class.
Answer: this

Fill-in Q5.
Having the same method name with different parameters is called method ___________.
Answer: overloading

Fill-in Q6.
___________ exceptions must be either caught or declared with throws.
Answer: Checked

Fill-in Q7.
The block that ALWAYS executes in exception handling is the ___________ block.
Answer: finally

Fill-in Q8.
JDBC stands for Java Database ___________.
Answer: Connectivity

Fill-in Q9.
The JDBC method for SELECT queries is ___________.
Answer: executeQuery()

OOP Using Java • Dr. George Asante • TBUDWORLD • Page 20


Fill-in Q10.
In JavaFX, the main window container is called a ___________.
Answer: Stage

Fill-in Q11.
The ___________ keyword prevents a variable from being changed after assignment.
Answer: final

Fill-in Q12.
Java compiles source code into ___________ which the JVM executes.
Answer: bytecode

Fill-in Q13.
The most restrictive access modifier in Java is ___________.
Answer: private

Fill-in Q14.
A class that cannot be instantiated is called an ___________ class.
Answer: abstract

Fill-in Q15.
The Java server-side networking class that listens for connections is ___________.
Answer: ServerSocket

Fill-in Q16.
Method ___________ occurs when a child class redefines a parent class method.
Answer: overriding

Fill-in Q17.
The ___________ keyword is used to manually throw an exception.
Answer: throw

Fill-in Q18.
A class can implement multiple ___________ but can only extend one class.
Answer: interfaces

Fill-in Q19.
PreparedStatement's method for INSERT/UPDATE/DELETE is ___________.
Answer: executeUpdate()

Fill-in Q20.
Converting a larger data type to a smaller one in Java is called ___________.
Answer: narrowing

OOP Using Java • Dr. George Asante • TBUDWORLD • Page 21


MATCHING QUESTIONS

15 Terms — Match Each Java Keyword to its Definition

Match each Java TERM in Column A with its DEFINITION in Column B:

Column A — Java Terms Column B — Definitions

OOP Using Java • Dr. George Asante • TBUDWORLD • Page 22


1 extends
.

2 implements
.

3 abstract
. A Used for class inheritance
.
4 finally
. B Used for interface implementation
.
5 static
. C Method or class without full implementation
.
6 this
. D Block that always executes in exception handling
.
7 super
. E Belongs to the class, not individual objects
.
8 new
. F Refers to current object instance
.
9 @Override
. G Refers to parent class
.
1 private
0 H Creates an object in memory
. .

1 VBox I. Annotation for method overriding


1
. J Most restrictive access modifier
.
1 PreparedStatement
2 K JavaFX vertical layout container
. .

1 ServerSocket L Prevents SQL injection in JDBC


3 .
.
M Listens for incoming client connections
1 bytecode .
4
. N Compiled Java code run by JVM
.
1 final
5 O Makes a variable constant or class
. . non-inheritable

MATCHING ANSWERS KEY

1. extends → A. Used for class inheritance

2. implements → B. Used for interface implementation

3. abstract → C. Method or class without full implementation

OOP Using Java • Dr. George Asante • TBUDWORLD • Page 23


4. finally → D. Block that always executes in exception handling

5. static → E. Belongs to the class, not individual objects

6. this → F. Refers to current object instance

7. super → G. Refers to parent class

8. new → H. Creates an object in memory

9. @Override → I. Annotation for method overriding

10. private → J. Most restrictive access modifier

11. VBox → K. JavaFX vertical layout container

12. PreparedStatement → L. Prevents SQL injection in JDBC

13. ServerSocket → M. Listens for incoming client connections

14. bytecode → N. Compiled Java code run by JVM

15. final → O. Makes a variable constant or class non-inheritable

OOP Using Java • Dr. George Asante • TBUDWORLD • Page 24


Code Hard, Pass Well! ■■

Java OOP — Notes + 40 MCQ + 25 T/F + 20 Fill-in + 15 Matching

TBUDWORLD • OOP Using Java • Dr. George Asante • ITE Group 4 — AAMUSTED

OOP Using Java • Dr. George Asante • TBUDWORLD • Page 25

You might also like