0% found this document useful (0 votes)
9 views

OOP Class

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)
9 views

OOP Class

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
You are on page 1/ 9

D—Object-oriented programming

1.1 Outline the general nature of an object. [2]

An object as an abstract entity and its components—data and actions.

Familiar examples from different domains might be people, cars, fractions, dates and music
tracks.

Abstract- hiding background details- only convey what is necessary

Object Instance of a class

Student- is a group RAM- one student- one instance


DEVID- one student- one instance

The collection of objects is called as class.

Animal
Cat- What does the cat do? How does it look?
Action Physical appearance
Behaviour Attribute

Object= Behaviour/method+ attribute/state/variable/data

Dog
Cow
Tiger

The object is an instance of a class that has state and behaviour

The object is an abstract entity that holds data.


States/attribute/property holds data
behaviour/method/actions on data
It occupies memory- has a lifecycle- construction- destruction

Future- class
Chair- object
Table- object

Data/ attribute- four legs, color, height, weight


Behaviour- sit, change the place, step on the chair
Student- blueprint

properties/attributes/data
Name-hold single value
Gender
Class
Address
subjects

behaviour/method/action
Exam()
Study()
play()

Class name

variable

method

Class- blueprint- template

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

Static will reflect the same for all.

public class student //project class


{
// instance variables- it belongs to student class
// private member variables with public methods-
encapsulation- private variables+public methods
private String name
private String Address;
private Boolean gender;
private Char Section;
private static String school; // class variable
//String Subject[]= new String[6]; //String
[]Subject= new String[6];

//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

}
}

1.2 Distinguish between an object (definition, template or class) and instantiation

Students must understand the difference in terms of code definitions, memory use and the
potential creation of multiple instantiated objects.

Class- Blueprint- template


Collection of obejctes. Which is also called as blueprint of objects.

It is a blueprint/template of defining methods and variables in the particular kind of


objects.
Syntax

Public class class_Name


{
Private int a; //Instance variable

void method1() //Instance methods


{
}
void method2() // method signature
{
//Method declarations
}
}

Java is purely case sensitive-


‘Java’ not equal to ‘java’

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.

LINK Connecting computational thinking and program design.

public class Student


{
private String name; //instance variable
private int grade; //instance variable

public Student() //default constructor


{
name="Raj";
grade=7;
}
public Student(String name, int grade1) //constructor
{
this.name=name;
grade=grade1;
}

public String getName() //getter/accessor method


{
return name;
}

public int getGrade() //getter/accessor method


{
return grade;
}

public void setName(String name) //setter/mutator method


{
this.name=name;
}
public void setGrade(int grade) //setter/mutator method
{
this.grade=grade;
}

public String printOutStudentInfo()


{
return name+" "+grade;
}
}
class pgm1
{
public static void main(String []args)
{
//Student object1=new Student(); // default constructor will be called
Student object=new Student("Mathe",5); //constructor with parameter
object.setName("RAM");
object.setGrade(6);
String name=object.getName();
System.out.println(name);
System.out.println(object.getGrade());

}
}
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 setName(String name){

}
public void setGrade(int grade){

public String printOutStudentInfo(){


return name;
}
}
Decomposition- making a big problem into smaller chunks, which can be easy to develop
and debug. Finally integrated.- modularity
A team can work on project for the different modules,
A simple example with 3–5 objects is suggested.
Examples related to D.1.1 could be
public class employees // Base class- parent class- super class
{
//payroll
//attendance
//leave
}

public class teacher extends employees // derived class- child class- sub class
{

}
// inheritance- ‘is a’ relation ship

public class admin extends employee


{
}

context - school- teachers, admin, accounts, HR, hod, coordinators,leadership


traffic simulation models,
calculators,
calendars,
media collections.

LINK Thinking abstractly. AIM 4 Applying thinking skills critically to decompose scenarios.

You might also like