0% found this document useful (0 votes)
6 views2 pages

OOPS Implementation in Java Notes

This document provides detailed notes on OOPS implementation in Java, covering key concepts such as classes, objects, data encapsulation, constructors, method overloading, inheritance, polymorphism, abstraction, interfaces, static members, inner classes, and string handling. Each topic includes explanations, code examples, and outputs to aid in theoretical and practical preparation. The content is structured to facilitate understanding of object-oriented programming principles and their application in Java.

Uploaded by

yashasvitemp64
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)
6 views2 pages

OOPS Implementation in Java Notes

This document provides detailed notes on OOPS implementation in Java, covering key concepts such as classes, objects, data encapsulation, constructors, method overloading, inheritance, polymorphism, abstraction, interfaces, static members, inner classes, and string handling. Each topic includes explanations, code examples, and outputs to aid in theoretical and practical preparation. The content is structured to facilitate understanding of object-oriented programming principles and their application in Java.

Uploaded by

yashasvitemp64
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

UNIT 2 – OOPS Implementation (Java) – Detailed Notes

This document covers complete Unit 2: OOPS Implementation in Java. Topics include: -
Classes, Objects, and Methods - Data Encapsulation - Constructors and Initialization
Blocks - Method Overloading and Static Members - Inheritance, Polymorphism, and
Abstraction - Interfaces, Inner Classes, and String Handling Each concept includes code
examples, explanations, and outputs for 20-mark theoretical and practical preparation.

1. Classes and Objects


A class is a template defining structure and behavior. An object is an instance of a class.
Example: class Student { int rollNo; String name; void display(){
[Link](rollNo+" "+name); } } Output: Roll No: 101 Name: Yashasvi
Explanation: Class defines attributes and methods. Objects use them via method calls.

2. Data Encapsulation
Encapsulation hides data using private members and public getters/setters. Example:
class Account { private double balance; public void setBalance(double b){ if(b>0)
balance=b; } public double getBalance(){ return balance; } } Output: Balance: 5000.0
Explanation: Access to 'balance' is restricted ensuring data security.

3. Constructors
Constructors initialize objects automatically. Example: class Student{
Student(){[Link]("Default Constructor");} Student(int r,String
n){[Link]("Parameterized Constructor");} } Output: Default Constructor
Parameterized Constructor Explanation: Constructors execute during object creation to set
initial values.

4. Method Overloading
Same method name, different parameters. Example: class MathOp{ int add(int a,int
b){return a+b;} double add(double a,double b){return a+b;} } Output: 30 31.0 Explanation:
Compile-time polymorphism achieved through method overloading.

5. Inheritance and Polymorphism


Inheritance enables reusability, polymorphism enables dynamic method binding. Example:
class Animal{void sound(){[Link]("Animal Sound");}} class Dog extends
Animal{void sound(){[Link]("Dog Barks");}} Output: Dog Barks Explanation:
Dog inherits Animal and overrides sound() for polymorphic behavior.

6. Abstraction and Interfaces


Abstract classes provide partial implementation; interfaces achieve full abstraction.
Example: interface Animal{void sound();} class Dog implements Animal{public void
sound(){[Link]("Dog Barks");}} Output: Dog Barks Explanation: Interfaces
define contracts for subclasses to implement.

7. Static Members
Static members belong to class, shared by all objects. Example: class Counter{static int
count=0;Counter(){count++;}} Output: Count=2 Explanation: Static variable retains its
value across objects.

8. Inner Classes and String Handling


Inner classes access outer class members. StringBuffer is mutable; StringTokenizer splits
strings. Example: StringTokenizer st=new StringTokenizer("Java is fun"); Output: Java is
fun Explanation: Tokenizer breaks a string into words efficiently.

You might also like