OOP Java BTech Handwritten Style Notes
OOP Java BTech Handwritten Style Notes
Syntax:
class ClassName {
int variable;
void method() {
// code
}
}
Syntax:
class Child extends Parent { }
Types of inheritance:
- Single
- Multilevel
- Hierarchical
Abstract class: Contains abstract methods (no body) and cannot be instantiated.
Interface: A completely abstract class with only method signatures.
Syntax:
interface InterfaceName {
void method();
}
class ClassName implements InterfaceName { }
The 'final' keyword is used to declare constants, prevent inheritance, and method
overriding.
Encapsulation means binding the data and the code that manipulates it together.
Use private variables and public getter/setter methods to achieve encapsulation.
Access Modifiers:
- private: accessible within the class
- public: accessible everywhere
- protected: accessible in the same package and subclasses
- default: accessible within the same package
Types:
- Checked (compile-time)
- Unchecked (runtime)
Syntax:
try {
// code
} catch(Exception e) {
// handle error
} finally {
// always executes
}
File Handling: Reading and writing files using FileReader, FileWriter, BufferedReader,
etc.
Example:
BufferedReader br = new BufferedReader(new FileReader("file.txt"));
Creating a thread:
- By extending Thread class
- By implementing Runnable interface
Collections Framework: Provides classes and interfaces for storing and manipulating
groups of data.