Содержание
- 2. Agenda Class and Object Access to data Fields of class Getters and Setters Constructors Methods of
- 3. A class is a prototype (template) from which objects are created An object is a software
- 4. class ClassName { // fields variable1; ... variableN; // constructors ClassName(parameter_list1){ // method body } ...
- 5. Class public class Student { private String lastName; private String firstName; private int age; private Student(){}
- 6. public class Student {...} private int age; public void print(){} Controlling Access to Members of a
- 7. Special Requirements to source files a source code file (.java) can have only one public class
- 8. Default values for fields
- 9. Widening (implicit or automatic) type casting take place when, the two types are compatible the target
- 10. Methods and overloading Methods are functions that are executed in context of object Always have full
- 11. Variable length arguments Methods in Java support arguments of variable length Should be last argument in
- 12. The following class uses public access control: public class Student { public String name; public int
- 13. The following class uses private access control: public class Student { private String name; public String
- 14. Student student = new Student(); student.setName(“Franko”); String nameStud = student.getName(); Getters and Setters set get
- 15. public class Sum { private int a, b, c; void setA(int m) { this.a = m;
- 16. Keyword "this" this always points to current object can't lose context like JavaScript not required in
- 17. Keyword 'static' Keyword 'static' indicates that some class member (method or field) is not associated with
- 18. Keyword 'static' public class Runner { public static void main (String[] args) { Helper.setMessage("hello"); Helper.print(); //
- 19. Constructors Constructors – special kind of methods called when instance created Name should be same as
- 20. Constructors public class Student { private String name; private int age; public static int count =
- 21. Student stud1 = new Student(); stud1.setName(“Dmytro”); stud1.setAge(25); Student stud2 = new Student(“Olga”); stud2.setAge(24); Student stud3 =
- 22. Private constructor Making constructor private will prevent creating instances of a class from other classes Still
- 23. System.out.println(student); com.edu.Student@659e0bfd @Override public String toString() { return "Student [lastNname=" + lastNname + ", firstName=" +
- 24. Create Console Application project in Java. Add class Student to the project. Class Student should consists
- 25. Create Console Application project in Java. Add class Employee to the project. Class Employee should consists
- 26. Create Console Application project in Java. Add class Person to the project. Class Person should consists
- 27. UDEMY course "Java Tutorial for Complete Beginners": https://www.udemy.com/java-tutorial/ Complete lessons 17-23:
- 29. Скачать презентацию