Download presentation
Presentation is loading. Please wait.
1
Objects as a programming concept
IB Computer Science
2
HL Topics 1-7, D1-4 1: System design 2: Computer Organisation
3: Networks 4: Computational thinking 5: Abstract data structures 6: Resource management 7: Control D: OOP
3
HL & SL D.3 Overview 1: System design 2: Computer Organisation
3: Networks D.3 Program development D.3.1 Define the terms: class, identifier, primitive, instance variable, parameter variable, local variable D.3.2 Define the terms: method, accessor, mutator, constructor, signature, return value D.3.3 Define the terms: private, protected, public, extends, static D.3.4 Describe the uses of the primitive data types and the reference class string D.3.5 Construct code to implement assessment statements D.3.6 Construct code examples related to selection statements D.3.7 Construct code examples related to repetition statements D.3.8 Construct code examples related to static arrays D.3.9 Discuss the features of modern programming languages that enable internationalization D.3.10 Discuss the ethical and moral obligations of programmers 4: Computational thinking 5: Abstract data structures 6: Resource management 7: Control D: OOP
4
Topic D.3.1 Define the terms: class, identifier, primitive, instance variable, parameter variable, local variable
5
Object Orientated Programming (OOP)
All objects have a state and behaviour. If we consider a dog, the its state is - name, breed, colour, and the behavio is - barking, wagging, running Software objects also have a state and behaviour. A software object's state is stored in fields and behaviour is shown via methods. n ur
6
object & class class Student private String name; private int age;
{ //constructor } public setStudent(String n) name = n; Object - Objects have states and behaviours. Example: A dog has states - colour, name, breed as well as behaviours -wagging, barking, eating. An object is an instance of a class. Class - A class can be defined as a template/blue print that describes the behaviours/states that object of its type support. }
7
identifier public readStudentName() {
An identifier is a pointer that explicitly identifies an object, class, interface, method, or variable. It allows a programmer to refer to the item from other places in the program. To make the most out of the identifiers you choose make them meaningful and follow the standard Java naming conventions. public readStudentName() { System.out.println(“Enter student name”); String answer = kb.nextLine(); }
8
identifier (rules)
9
primitive (data type) char byte short int long float double boolean
Primitive Type Size Minimum Value Maximum Value char 16-bit Unicode 0 Unicode 216-1 byte 8-bit -128 +127 short -215 (-32,768) +215-1 (32,767) int 32-bit -231 (-2,147,483,648) +231-1 (2,147,483,647) long 64-bit -263 (-9,223,372,036,854,775,808) +263-1 (9,223,372,036,854,775,807) float 32-bit IEEE 754 floating-point numbers double 64-bit IEEE 754 floating-point numbers boolean 1-bit true or false
10
variable (in general) A variable provides us with named storage that our programs can manipulate. They must be declared before they can be used. int a, b, c; // Declares three ints, a, b, and c. int a = 10, b = 10; // Example of initialization byte B = 22; // initializes a byte type variable B. double pi = ; // declares and assigns a value of PI. char a = 'a'; // the char variable a is given value 'a'
11
3 Variable types instance variable: A variable in a class from which every instantiated object gets its own copy. If a class called people would have an instance variable called age, every object of this class would have its own variable called age. parameter variable: A variable that is passed along to a function that is called to perform operations with. In Java it is the argument passed in the brackets with the function caller. local variable: A variable declared inside a function. This variable is only known and accessible by the function it is declared inside.
12
instance variable (global)
class Student private String name; private int age; Student() { //constructor } public setStudent(String n) Instance variables are declared inside a class, but outside a method, constructor or any block name = n; }
13
local variable Local variables are declared inside
methods, constructors, or blocks public readStudentName() { System.out.println(“Enter student name”); String answer = kb.nextLine(); }
14
parameter variable Variable that is declared inside the brackets of a method. It only exists in that method. public setDogType(String n) { //something }
Similar presentations
© 2024 SlidePlayer.com. Inc.
All rights reserved.