You are on page 1of 24

OOPS

in Java
User defined data type cars

int, float, double, char. String, Type

class- 124-D + 50 students


No.

I
Roll
common

125
percentage
properties

Height
User defined data type

So students

Name -
String arr[so]
Roll No. -> int bor(so]

percentage - double (r(so]


Classes - creation

new data
type a student

Namte ↓
->
Roll No

percentage
Classes - creation
/Pet
name

-> data
X

type
creation
Objects - creation -

Class Name objectname new


=
Classname();

Student st new
= Student 1); At
S1

Alto, Wagon, Swift -> Manti Cars

real life entities


·
Objects are

a classes are blueprints


State True or False

~1) OOPS refer to using objects in programming.


2) Class is user defined blueprint through which
u
objects are created.
3) Objects of same class have different
properties / attributes. X
~
4) Objects are instance of class.
-
Array v/s Class -> user defined data type

-
L
similar datatypes to store -
multiple

multiple attributes
eK esa objectcrate karna ho s
Scanner class yaad hai?
functions:
execlass to

·
We have to declare the class outside main.

· classes are passed by reference


d

user defined data type


Class in different file.
L
but
same package..

·
Diff. package me class banai to?
at
values:
percent
public class Student [ pro,
-
int uno;

String name;

double percent;
3
S1-create
Access Modifiers
1) Public - all packages
2) Private - same class
3) Default - same package
Getters and Setters
-

class
functions of a

private,

↓Y access

changes
“this” keyword

int
private uno;

public void setRno(int wno) [

this 24o= wno;

3
What is a Constructor?
Student
->
percent
L
L
name

2nO

S1
Student new
=
Student ("Ragbar", 76,92.1);
What is final keyword ?
L

attribute
What is static keyword ?
Student 31 new
=

....

class Student [ percent no


of
name,
Ano

int uno;
#
SL

string name;

Student S2,
double percent;
53
int number ofstudents;

3
I
it
53
eno Name per
W
w St 76
Raghav 88.6
-
~ ~no name per
~
S2 67 Rahul 98.3
~

z40 name percent


99
static int no of students; 53 Rohan 91.3

23

Output number of students

· I

·
2

03
static functions
d
Used if we want
to access a function in the class

through just classname function.


Ques : Make Fraction class.
3.3 7-7
3
I
+

+ -

7 =3

class Fraction [
2 I =

int num;

int den;

3

Eadd(f2, f2);Simflify ();
sub (f1, f2)
Ques : Make Fraction class.

3-
Yet
d Fraction -1,
f2
21 %14
=
0 X
L
=

- - 343 add 2 (f1, f2)


=

+1 f2 +3 ⑰
Ques : Make your own ArrayList.
1

Dynamic Array
3 size 4=

An
-> d3.

ii)
11 I
arr. add()

aur,get()
THANK YOU
d

Maza Aagaya

You might also like