1 fields class fields methods class methods constructors
- Slides: 23
Κλάσεις (1) – Πεδία (fields). – Πεδία κλάσεων (class fields). – Μεθόδους (methods). – Μεθόδους κλάσεων (class methods). – Μεθόδους δημιουργίας (constructors). – Αναφορά this. 12/4/2020 public class Counter { private static int OBJECTS = 0; int value = 0; public Counter() { this(0); } Counter(int value) { Counter. OBJECTS++; this. value = value; } public int increment() { return ++this. value; } } Εισαγωγή στη Java για όσους γνωρίζουν C++ 5
Κλάσεις (2) – Μπλοκ στατικής αρχικοποίησης (static initializers). – Εσωτερικές κλάσεις (inner classes). – Ανώνυμες εσωτερικές κλάσεις (anonymous inner classes). – Προσοχή: • Κλάση • Αντικείμενο • Αναφορά 12/4/2020 public class Counter { private static Object. Counter OBJECTS; int value = 0; static { Counter. OBJECTS = new Object. Counter(); } private class Object. Counter { //… } } Εισαγωγή στη Java για όσους γνωρίζουν C++ 6
Κληρονομικότητα (2) public abstract class Shape { public Shape() {…} abstract void draw(…); } public class Circle extends Shape { Point centre; int radius; public Circle(int radious) { super(); } void draw(…) {…} Shape Circle public final class Text extends Shape { //… } Text … } 12/4/2020 Εισαγωγή στη Java για όσους γνωρίζουν C++ 9
Κληρονομικότητα (4) public interface Shape { abstract void draw(…); } public interface Text { abstract String get. Text(); } Shape Text Circled Text public class Circle implements Shape { Point centre; public class Circled. Text int radius; implements Shape, Text { public void draw(…) {…} void draw(…) { public String get. Text() {…} // … } } } 12/4/2020 Εισαγωγή στη Java για όσους γνωρίζουν C++ 11
Εξαιρέσεις (2) java. lang. Throwable java. lang. Error ex ex 12/4/2020 java. lang. Exception ex java. lang. Runtime Exception Input. Stream in = null; try { in = new File. Input. Stream( new File(“file. dat”)); } catch(File. Not. Found. Exception fnfe) { // … } catch(Security. Exception se) { // … } finally { // … } Εισαγωγή στη Java για όσους γνωρίζουν C++ 18
Επέκταση Thread public class Print. Thread extends Thread { String msg; public Print. Thread(String msg) { super(); this. msg = msg; } public class Thread. Test { public static void main(String[] s) { Print. Thread t 1 = new Print. Thread(“a”); Print. Thread t 1 = new Print. Thread(“b”); t 1. start(); t 2. start(); try { t 1. join(); t 2. join(); } catch(Interrupted. Exception ie) {} public void run() { for (int k=0; k<100; k++) { System. out. println( “[” + k + “] ” + this. msg); } } } 12/4/2020 Εισαγωγή στη Java για όσους γνωρίζουν C++ 21
Υλοποίηση Runnable public class Print. Thread implements Runnable { String msg; public Print. Thread(String msg) { this. msg = msg; } public class Thread. Test { public static void main(String[] s) { Print. Thread t 1 = new Thread( new Print. Thread(“a”)); Print. Thread t 1 = new Thread( new Print. Thread(“b”)); t 1. start(); t 2. start(); try { t 1. join(); t 2. join(); } catch(Interrupted. Exception ie) {} public void run() { for (int k=0; k<100; k++) { System. out. println( “[” + k + “] ” + this. msg); } } } 12/4/2020 Εισαγωγή στη Java για όσους γνωρίζουν C++ 22
- Method signature consists of
- Considerate constructors scoring matrix
- Considerate constructors best practice hub
- Types of constructor in c++
- Constructor in java
- Red fields to green fields
- Indirect wax pattern
- Ck metrics
- Static collection
- Java math class functions
- Norm rule fields
- How many fields in computer science
- Electric forces and fields concept review
- All good gifts around us are sent from heaven above
- The apices of the lungs
- Alternative cover test
- 6 cardinal fields of gaze
- Stealing by carol ann duffy
- Slope fields ap calculus
- New consultant training
- Assembly mips tutorial
- Rda fields
- Learning: module 26: magnetic forces and fields
- Magnetism lesson outline answer key