Оцените презентацию от 1 до 5 баллов!
Тип файла:
ppt / pptx (powerpoint)
Всего слайдов:
28 слайдов
Для класса:
1,2,3,4,5,6,7,8,9,10,11
Размер файла:
852.50 kB
Просмотров:
68
Скачиваний:
0
Автор:
неизвестен
Слайды и текст к этой презентации:
№1 слайд![Class and Object Java Core](/documents_6/d9ef47a30e529b6d4a7c173f6057ff70/img0.jpg)
Содержание слайда: Class and Object
Java Core
№2 слайд![Agenda Class and Object](/documents_6/d9ef47a30e529b6d4a7c173f6057ff70/img1.jpg)
Содержание слайда: Agenda
Class and Object
Access to data
Fields of class
Getters and Setters
Constructors
Methods of class
Creating objects
Examples
№3 слайд![Class and Object A class is a](/documents_6/d9ef47a30e529b6d4a7c173f6057ff70/img2.jpg)
Содержание слайда: Class and Object
A class is a prototype (template) from which objects are created
An object is a software bundle of related state and behavior
№4 слайд![Class lt access specifier gt](/documents_6/d9ef47a30e529b6d4a7c173f6057ff70/img3.jpg)
Содержание слайда: Class
<access specifier> class ClassName {
// fields
<access specifier> <data type> variable1;
...
<access specifier> <data type> variableN;
// constructors
<access specifier> ClassName(parameter_list1){
// method body }
...
<access specifier> ClassName(parameter_listN){
// method body }
// methods
<access specifier> <return type> method1(parameter_list){
// method body }
...
<access specifier> <return type> methodN(parameter_list){
// method body }
№5 слайд![Class](/documents_6/d9ef47a30e529b6d4a7c173f6057ff70/img4.jpg)
№6 слайд![Access to data public class](/documents_6/d9ef47a30e529b6d4a7c173f6057ff70/img5.jpg)
Содержание слайда: Access to data
public class Student {...}
private int age;
public void print(){}
Controlling Access to Members of a Class
Class Package Subclass World
private Y — — —
(not) Y Y — —
protected Y Y Y —
public Y Y Y Y
№7 слайд![Special Requirements to](/documents_6/d9ef47a30e529b6d4a7c173f6057ff70/img6.jpg)
Содержание слайда: Special Requirements to source files
a source code file (.java) can have only one public class
name of this class should be exactly the same of file name before extension (including casing)
source code file can have any number of non-public classes
most code conventions require use only one top-level class per file
№8 слайд![Default values for fields](/documents_6/d9ef47a30e529b6d4a7c173f6057ff70/img7.jpg)
Содержание слайда: Default values for fields
№9 слайд![Type casting Widening](/documents_6/d9ef47a30e529b6d4a7c173f6057ff70/img8.jpg)
Содержание слайда: Type casting
Widening (implicit or automatic) type casting take place when, the two types are compatible the target type is larger than the source type
№10 слайд![Methods and overloading](/documents_6/d9ef47a30e529b6d4a7c173f6057ff70/img9.jpg)
Содержание слайда: Methods and overloading
Methods are functions that are executed in context of object
Always have full access to data of object
Object can have multiple methods with same name but different signature (type and order of parameters)
Signature doesn't include return type, methods can't be overloaded by return types
№11 слайд![Variable length arguments](/documents_6/d9ef47a30e529b6d4a7c173f6057ff70/img10.jpg)
Содержание слайда: Variable length arguments
Methods in Java support arguments of variable length
Should be last argument in method definition
№12 слайд![Access to fields The](/documents_6/d9ef47a30e529b6d4a7c173f6057ff70/img11.jpg)
Содержание слайда: Access to fields
The following class uses public access control:
public class Student {
public String name;
public int age;
...
}
Student stud = new Student();
stud.name = “Krystyna”;
stud.age = 22;
№13 слайд![Getters and Setters The](/documents_6/d9ef47a30e529b6d4a7c173f6057ff70/img12.jpg)
Содержание слайда: Getters and Setters
The following class uses private access control:
public class Student {
private String name;
public String getName() {
return this.name;
}
public void setName(String name) {
this.name = name;
}
}
№14 слайд![Getters and Setters Student](/documents_6/d9ef47a30e529b6d4a7c173f6057ff70/img13.jpg)
Содержание слайда: Getters and Setters
Student student = new Student();
student.setName(“Franko”);
String nameStud =
student.getName();
№15 слайд![Getters and Setters can be](/documents_6/d9ef47a30e529b6d4a7c173f6057ff70/img14.jpg)
Содержание слайда: Getters and Setters can be Complex
public class Sum {
private int a, b, c;
void setA(int m) { this.a = m; c = a + b; }
void setB(int n) { this.b = n; c = a + b; }
int getA() { return this.a; }
int getB() { return this.b; }
int getC() { return this.c; }
public void sum(int m, int n) {
this.a = m; this.b = n;
this.c = m + n;
}
}
№16 слайд![Keyword quot this quot this](/documents_6/d9ef47a30e529b6d4a7c173f6057ff70/img15.jpg)
Содержание слайда: Keyword "this"
this always points to current object
can't lose context like JavaScript
not required in most cases
often needed to distinguish between parameters and fields:
№17 слайд![Keyword static Keyword static](/documents_6/d9ef47a30e529b6d4a7c173f6057ff70/img16.jpg)
Содержание слайда: Keyword 'static'
Keyword 'static' indicates that some class member (method or field) is not associated with any particular object
Static members should be accessible by class name (good practice, not required by language itself)
№18 слайд![Keyword static](/documents_6/d9ef47a30e529b6d4a7c173f6057ff70/img17.jpg)
Содержание слайда: Keyword 'static'
№19 слайд![Constructors Constructors](/documents_6/d9ef47a30e529b6d4a7c173f6057ff70/img18.jpg)
Содержание слайда: Constructors
Constructors – special kind of methods called when instance created
Name should be same as a class
Class may have multiple overloaded constructors
If not provided any constructor, Java provides default parameterless empty constructor
№20 слайд![Constructors](/documents_6/d9ef47a30e529b6d4a7c173f6057ff70/img19.jpg)
Содержание слайда: Constructors
№21 слайд![Creating objects new Student](/documents_6/d9ef47a30e529b6d4a7c173f6057ff70/img20.jpg)
Содержание слайда: Creating objects – new()
Student stud1 = new Student();
stud1.setName(“Dmytro”);
stud1.setAge(25);
Student stud2 =
new Student(“Olga”);
stud2.setAge(24);
Student stud3 =
new Student(“Ivan”, 26);
int n = Student.count;
№22 слайд![Private constructor Making](/documents_6/d9ef47a30e529b6d4a7c173f6057ff70/img21.jpg)
Содержание слайда: Private constructor
Making constructor private will prevent creating instances of a class from other classes
Still allows creating instances inside static methods of the class
№23 слайд![toString System.out.println](/documents_6/d9ef47a30e529b6d4a7c173f6057ff70/img22.jpg)
Содержание слайда: toString()
System.out.println(student);
com.edu.Student@659e0bfd
@Override
public String toString() {
return "Student
[lastNname=" + lastNname +
", firstName=" + firstName +
", age=" + age + "]";
}
Student [lastNname=Ivanov, firstName=Vasiy, age=22]
№24 слайд![Example Create Console](/documents_6/d9ef47a30e529b6d4a7c173f6057ff70/img23.jpg)
Содержание слайда: Example
Create Console Application project in Java.
Add class Student to the project.
Class Student should consists of
two private fields: name and rating;
properties for access to these fields
static field avgRating – average rating of all students
default constructor and constructor with parameters
methods:
betterStudent - to definite the better student (between two, return true or false)
toString - to output information about student
changeRating - to change the rating of student
In the method main() create 3 objects of Student type and input information about them.
Display the average and total rating of all student.
№25 слайд![Practical task Create Console](/documents_6/d9ef47a30e529b6d4a7c173f6057ff70/img24.jpg)
Содержание слайда: Practical task
Create Console Application project in Java.
Add class Employee to the project.
Class Employee should consists of
three private fields: name, rate and hours;
static field totalSum
properties for access to these fields;
default constructor, constructor with 2 parameters (name and rate) and constructor with 3 parameters;
methods:
salary - to calculate the salary of person (rate * hours)
toString - to output information about employee
changeRate - to change the rate of employee
bonuses – to calculate 10% from salary
In the method main() create 3 objects of Employee type. Input information about them.
Display the total hours of all workers to screen
№26 слайд![Homework Create Console](/documents_6/d9ef47a30e529b6d4a7c173f6057ff70/img25.jpg)
Содержание слайда: Homework
Create Console Application project in Java.
Add class Person to the project.
Class Person should consists of
two private fields: name and birthYear (the birthday year)
properties for access to these fields
default constructor and constructor with 2 parameters
methods:
age - to calculate the age of person
input - to input information about person
output - to output information about person
changeName - to change the name of person
In the method main() create 5 objects of Person type and input information about them.
№27 слайд![UDEMY course quot Java](/documents_6/d9ef47a30e529b6d4a7c173f6057ff70/img26.jpg)
Содержание слайда: UDEMY course "Java Tutorial for Complete Beginners": https://www.udemy.com/java-tutorial/
UDEMY course "Java Tutorial for Complete Beginners": https://www.udemy.com/java-tutorial/
Complete lessons 17-23:
№28 слайд![The end](/documents_6/d9ef47a30e529b6d4a7c173f6057ff70/img27.jpg)
Содержание слайда: The end