OOP 2 Marks Unit I To V
OOP 2 Marks Unit I To V
UNIT - I
1. What is Java?
5. Define Class
A class is a collection of similar objects and it contains data and methods that operate on that
data. In other words ― Class is a blueprint or template for a set of objects that share a
common structure and a common behavior. It is a logical entity.
1
Mrs. B.Pandiselvi , AP/CSE - RVCE
CS3391 Object Oriented Programming 2-Marks III/SEM /CSE
7.Define Object.
Any entity that has state and behavior is known as an object. Object is an instance of a class.
• For example: chair, pen, table, keyboard, bike etc. It can be physical and logical.
• The object of a class can be created by using the new keyword in Java Programming
language.
Syntax:
• class_name object_name = new class_name;
• (or) class_name object_name;
• object_name = new class_name();
2
Mrs. B.Pandiselvi , AP/CSE - RVCE
CS3391 Object Oriented Programming 2-Marks III/SEM /CSE
• For Example: Pen is an object. Its name is Reynolds, color is white etc. known as its state.
It is used to write, so writing is its behavior
10.Define Polymorphism:
• Polymorphism is a concept by which we can perform a single action by different
ways. It is the ability of an object to take more than one form.
• The word "poly" means many and "morphs" means forms. So polymorphism
means many forms.
• Two types of polymorphism:
1. Compile time polymorphism / Method Overloading: - In this method, object is
bound to the function call at the compile time itself.
2. Runtime polymorphism / Method Overriding: - In this method, object is bound to
the function call only at the run time.
• In java, we use method overloading and method overriding to achieve
polymorphism.
• Example:
1. draw(int x, int y, int z)
2. draw(int l, int b)
3. draw(int r)
3
Mrs. B.Pandiselvi , AP/CSE - RVCE
CS3391 Object Oriented Programming 2-Marks III/SEM /CSE
11.Define Abstraction:
• Abstraction refers to the act of representing essential features without including
the background details or explanations. i.e., Abstraction means hiding lower-
level details and exposing only the essential and relevant details to the users.
• For Example: - Consider an ATM Machine; All are performing operations on the
ATM machine like cash withdrawal, money transfer, retrieve mini-
statement…etc. but we can't know internal details about ATM.
• Abstraction provides advantage of code reuse.
• Abstraction enables program open for extension.
• In java, abstract classes and interfaces are used to achieve Abstraction.
12.Define Inheritance:
Inheritance is a process of deriving a new class from existing class, also called as
“extending a class”. When an existing class is extended, the new (inherited) class has all the
properties and methods of the existing class and also possesses its own characteristics.
The class whose property is being inherited by another class is called “base class” (or)
“parent class” (or) “super class”.
The class that inherits a particular property or a set of properties from the base class is called
“derived class” (or) “child class” (or) “sub class”.
• For example:- In a child and parent relationship, all the properties of a father are
inherited by his son.
• Syntax of Java Inheritance
4
Mrs. B.Pandiselvi , AP/CSE - RVCE
CS3391 Object Oriented Programming 2-Marks III/SEM /CSE
5
Mrs. B.Pandiselvi , AP/CSE - RVCE
CS3391 Object Oriented Programming 2-Marks III/SEM /CSE
· Transfer statements: Loop Control Statements/ Jump Statements: break, continue, return,
try-catch-finally and assert.
We use control statements when we want to change the default sequential order of execution.
//Statements }
Types of constructors
There are two types of constructors:
1. Default constructor
2. no-arg constructor
3. Parameterized constructor
6
Mrs. B.Pandiselvi , AP/CSE - RVCE
CS3391 Object Oriented Programming 2-Marks III/SEM /CSE
UNIT - II
1. Define Method Overloading and its Advantages, way to achieve overloading.
Method Overloading is a feature in Java that allows a class to have more than one methods
having same name, but with different signatures (Each method must have different number of
parameters or parameters having different types and orders).
Advantage:
Method Overloading increases the readability of the program.
Provides the flexibility to use similar method with different parameters.
Three ways to overload a method
1. Number of parameters. (Different number of parameters in argument list)
For example: This is a valid case of overloading
add(int, int)
add(int, int, int)
2. Data type of parameters. (Difference in data type of parameters)
For example:
add(int, int)
add(int, float)
3. Sequence of Data type of parameters.
For example:
add(int, float)
add(float, int)
7
Mrs. B.Pandiselvi , AP/CSE - RVCE
CS3391 Object Oriented Programming 2-Marks III/SEM /CSE
{
// body of class }
8
Mrs. B.Pandiselvi , AP/CSE - RVCE
CS3391 Object Oriented Programming 2-Marks III/SEM /CSE
4. Hierarchical Inheritance
5. Hybrid Inheritance (not support)
9
Mrs. B.Pandiselvi , AP/CSE - RVCE
CS3391 Object Oriented Programming 2-Marks III/SEM /CSE
UNIT - III
1. Define Exception.
An Exception is an event that occurs during program execution which disrupts the normal flow of
a program. It is an object which is thrown at runtime.
Occurrence of any kind of exception in java applications may result in an abrupt termination of
the JVM or simply the JVM crashes.
Exceptions can be classified into two types: There is no such classification for
3. a) Checked Exceptions errors. Errors are always unchecked.
b) Unchecked Exceptions
10
Mrs. B.Pandiselvi , AP/CSE - RVCE
CS3391 Object Oriented Programming 2-Marks III/SEM /CSE
1. User-Defined Exception
2. Built - in - Exception
i)Checked Exceptions: ii)Unchecked Exceptions(RunTimeException
1. ClassNotFoundException 1. ArrayIndexOutOfBoundsException
2. CloneNotSupportedException 2. ArithmeticException
3. IllegalAccessException 3. NullPointerException.
4. MalformedURLException.
5. NoSuchFileException
6. NoSuchMethodException
7. IOException
11
Mrs. B.Pandiselvi , AP/CSE - RVCE
CS3391 Object Oriented Programming 2-Marks III/SEM /CSE
7. Define Thread.
A thread is a lightweight sub-process that defines a separate path of execution. It is the smallest
unit of processing that can run concurrently with the other parts (other threads) of the same
process.
Threads are independent.
If there occurs exception in one thread, it doesn't affect other threads.
It uses a shared memory area.
8.Define Multithreading.
Multithreading is a technique of executing more than one thread, performing different tasks,
simultaneously.
Multithreading enables programs to have more than one execution paths which executes
concurrently. Each such execution path is a thread. For example, one thread is writing
content on a file at the same time another thread is performing spelling check.
12
Mrs. B.Pandiselvi , AP/CSE - RVCE
CS3391 Object Oriented Programming 2-Marks III/SEM /CSE
by the Java Virtual Machine when an exception is thrown to indicate the location and
progression of the program up to the point of the exception. They are displayed whenever a Java
program terminates with an uncaught exception
13
Mrs. B.Pandiselvi , AP/CSE - RVCE
CS3391 Object Oriented Programming 2-Marks III/SEM /CSE
UNIT - IV
1. Define Java I/O.
Java I/O (Input and Output) is used to process the input and produce the output.
• Java uses the concept of stream to make I/O operation fast.
• These streams support all the types of objects, data-types, characters, files etc to fully
execute the I/O operations.
• The java.io package contains all the classes required for input and output operations.
• Then, we will create an object of Scanner class which will be used to get input from the
user.
JAVA INPUT
import java.util.Scanner;
Scanner input = new Scanner (System.in);
int number = input.nextInt();
JAVA OUTPUT
Simply use System.out.println(), System.out.print() or System.out.printf() to send output
to standard output (screen).system is a class and out is a public static field which accepts
output data.
2.What's the difference between println (), print () and printf ()?
• print () - prints string inside the quotes.
• println () - prints string inside the quotes similar like print() method. Then the cursor
moves to the beginning of the next line.
• printf () - it provides string formatting
3. Define Stream.
A Stream is a sequence of data or it is an abstraction that either produces or consumes
information. In other simple words it is a flow of data from which you can read or write data
to it. It’s called a stream because it's like a stream of water that continues to flow.
14
Mrs. B.Pandiselvi , AP/CSE - RVCE
CS3391 Object Oriented Programming 2-Marks III/SEM /CSE
7. What is File Handling in Java? Write down the File Operations in Java.
• File handling in Java implies reading from and writing data to a file.
• The File class from the java.io package, allows us to work with different formats of
files.
• In order to use the File class, you need to create an object of the class and specify the
filename or directory name.
Basically, you can perform four operations on a file. They are as follows:
1) Create a File
2) Get File Information
3) Write To a File
4) Read from a File
UNIT - V
1. What is JavaFX?
JavaFX is a set of graphics and media packages that enable developers to design, create, test,
debug, and deploy desktop applications and Rich Internet Applications (RIA) that operate
consistently across diverse platforms. The applications built in JavaFX can run on multiple
platforms including Web, Mobile, and Desktops.
15
Mrs. B.Pandiselvi , AP/CSE - RVCE
CS3391 Object Oriented Programming 2-Marks III/SEM /CSE
16
Mrs. B.Pandiselvi , AP/CSE - RVCE
CS3391 Object Oriented Programming 2-Marks III/SEM /CSE
17
Mrs. B.Pandiselvi , AP/CSE - RVCE
CS3391 Object Oriented Programming 2-Marks III/SEM /CSE
18
Mrs. B.Pandiselvi , AP/CSE - RVCE
CS3391 Object Oriented Programming 2-Marks III/SEM /CSE
11. Define JavaFX Menus, MenuItem and MenuBar and its constructors.
Menu is a popup menu that contains several menu items that are displayed when the
user clicks a menu. The user can select a menu item after which the menu goes into a hidden
state.
MenuBar is usually placed at the top of the screen which contains several menus. JavaFX
MenuBar is typically an implementation of a menu bar.
Constructor of the MenuBar class are:
1. MenuBar(): creates a new empty menubar.
2. MenuBar(Menu... m): creates a new menubar with the given set of menu.
19
Mrs. B.Pandiselvi , AP/CSE - RVCE