OOP Class
OOP Class
Familiar examples from different domains might be people, cars, fractions, dates and music
tracks.
Animal
Cat- What does the cat do? How does it look?
Action Physical appearance
Behaviour Attribute
Dog
Cow
Tiger
Future- class
Chair- object
Table- object
properties/attributes/data
Name-hold single value
Gender
Class
Address
subjects
behaviour/method/action
Exam()
Study()
play()
Class name
variable
method
STUDENT
Name: String
gender: Boolean
Section: Char
Address: String
Subject[]:String
exam()
study()
play()
RAM object
Name: RAM
gender: M
Section: B
Address: Mumbai
Subject[]:
maths,phy,che
exam()
study()
play()
DEVID
Name: Devid
gender: M
Section: A
Address:
Hyderabad
Subject[]: Maths,
CS, Eco
exam()
study()
play()
Change in the instance variable will not affect the other objects- instance variables
//instance members
public void setData(String name,Boolean gender,Char
Section,String Address) //method signature
//public- access specifier- public/private/protected
//void- return type- String, int, char, float,
Object
//setData()- name of the method
//(String name,Boolean gender,Char Section,String
Address) -parameters- local variables
{
}
public int exam()
{
return 1;
}
public void study()
{
}
protected void play()
{
}
}
class group extends student // group inherits the
properties of student class-
//group- sub class/ child class/ derived class
// student- super class
{
}
public class mainclass //Driver class
{
public static void main(String []args)
{
//className objectName=new className(); creating
instance/object/ initialization
student RAM=new student(); //object1
student DEVID=new student(); //object 2
}
}
Students must understand the difference in terms of code definitions, memory use and the
potential creation of multiple instantiated objects.
Object Initialization
className objectName=new className() // class constructor
A O=new A();
A- class name
O- Object name
New- keyword which is used to initiate the object.
1.3 Construct unified modelling language (UML) diagrams to represent object designs.
}
}
public class Student
{
private String name;
private int grade;
public Student(){
}
public Student(String name, int grade){
}
public String getName(){
return name;
}
public int getGrade(){
return grade;
}
}
public void setGrade(int grade){
public class teacher extends employees // derived class- child class- sub class
{
}
// inheritance- ‘is a’ relation ship
LINK Thinking abstractly. AIM 4 Applying thinking skills critically to decompose scenarios.