Object Oriented Programming-Classes and Objects
Previous
|< Arrays in Java |
Next
Objects and methods >| |
One of the ideas behind the object-oriented software is that the software is organized in a way that suits the way of thinking an object-oriented brain. Instead of the machine instructions that change the bits in the main memory, we want "things" that something "works". Of course, nothing has changed at the machine level, bit patterns continue to change via machine instructions. The change is that we do not have to think that way.
Question: List several objects.
Pencil, keyboard, shoes, table
Question: What is the characteristic of an object?
Question: List several objects.
Pencil, keyboard, shoes, table
Question: What is the characteristic of an object?
- The building is made of tangible material
- The building behaves as a whole, composed of parts
- The building has features
- The facility can do some things and some actions can take place on it.
- has an identity (it behaves as a whole)
- has a state (has properties that can be changed)
- has behavior (can do some things and some actions can be done on it)
VIDEO LESSON
Video 1: Classes and objects -part 1
In this presentation, we will show how to create classes and objects in the JAVA programming language.
The idea of object-oriented programming is to present data in software in a similar way as in nature.
The idea of object-oriented programming is to present data in software in a similar way as in nature.
Complex data-objects
To reserve the memory of the object we use the following form:
type_name data_name = new constructor (parameters_constructor);
For the data type, the name of the Class to which the object belongs is used. For example. if the object belongs to the Scanner class then the definition of the object that we call the reader would be:
Scanner reader=new Scanner(System.in);
Defining a complex data.
Software objects imitate objects from nature, so that both have:
- Properties
- Behavior
- State
Class-as a description of the object
The object class is actually a description of all objects that belong to it, and these are objects that have the same:
- Properties
- Behavior-described by methods
By defining an object we created it by description (Class) and it will have the properties and methods listed there:
Class methods Scanner
There are some methods in the Scanner class, for example:
Software objects have a state. The part of the memory occupied by the software object is used for variables that contain values.
Software objects have behavior. Part of the memory they occupy is spent on storing methods (programs) that allow the facility to "do something." The object does something when one of its methods is executed
- nextInt () - this method takes from the standard input the data typed on the keyboard, converts it into an integer.
- nextDouble () - this method takes from the standard input the data typed on the keyboard, converts it into a real number.
- identity (acts as a whole)
- state (has properties that can change)
- Behavior (can do some things and some actions can be done on it)
Software objects have a state. The part of the memory occupied by the software object is used for variables that contain values.
Software objects have behavior. Part of the memory they occupy is spent on storing methods (programs) that allow the facility to "do something." The object does something when one of its methods is executed
Assuming that for an object, we take the initial dialog window from the displayed application
The following figure shows the image of that object in the memory
From the displayed image of that object in the memory we conclude:
- The tiles in the image represent the bytes in the memory that the object occupies.
- This object has some variables, the width of the Dialog, the height of the Dialog, and the textUsual, as well as some methods that control its behavior
- The software object consists of variables and methods
Object class in java
- Class is a set of objects that have a common structure and behavior.
- One object is a copy of a class
- A set of common features of an object and methods that represent the behavior of these objects are described in their class
Classes and objects on the example of points in the plane:
text of the task: Create 3 objects representing three points in level A, B, C. Move point A to the new A1 position.
§Point the coordinates of the points after the move. Data points are given in the picture.
§Point the coordinates of the points after the move. Data points are given in the picture.
We note that all three objects belong to the same class because they have the same properties x and y.There will be 3 different expansions (objects) of the same class
The status of point A will change during the program, but not the properties.
To create objects, we first need to create a class that will describe them. Class we will call Tacka. In it we will list the common attributes x and y that will have all 3 objects.
-
The status of point A will change during the program, but not the properties.
To create objects, we first need to create a class that will describe them. Class we will call Tacka. In it we will list the common attributes x and y that will have all 3 objects.
-
Class Point
Previous
|< Arrays in Java |
Next
Objects and methods >| |