class Employee int salary int bonus public void


































- Slides: 34







Παράδειγμα class Employee { int salary; int bonus; public void set. Salary (int employee. Salary) { salary = employee. Salary } int get. Salary ( ) { return salary; } } Employee John; John =new Employee ( ); //Sos αγνοείτε πάντα τις εντολές με κόκκινο !!!!! //Είναι απαραίτητες αλλά εξηγούνται σε επόμενες διαφάνειες!!! John. set. Salary (1200); John. bonus = 500; int some. Salary = John. get. Salary ( ); 7


Ένα παράδειγμα κληρονομικότητας class Parent { int a; public void foo () {…. . } } class Child extends Parent { int b; public void test( ); } Parent Child my. Child; my. Child = new Child( ); // Please ignore this red line for now my. Child. foo(); my. Child. a = some. Integer ; Έγκυρες κλήσεις, εφόσον η κλάση Child κληρονομεί μεταβλητές και μεθόδους της κλάσης Parent 9







Παραδείγματα κατασκευαστών class Rectangle { int height; int width; public Rectangle ( ) { height = 1; width = 1; } public Rectangle (int rect. Height, int rect. Width) { height = rect. Height; width = rect. Width; } } // Τέλος κλάσης Rectangle 16


Παράδειγμα πολλαπλών α) κατασκευαστών my. Class Test 1 = new my. Class( ); class my. Class { int a; int b; my. Class() { a = 0; b = 0; } my. Class( int alpha, int beta ) { a = alpha; b=beta; } } Καλείται ο constructor χωρίς ορίσματα (default constructor), συνεπώς: a = 0 b = 0 my. Class Test 2 = new my. Class( 2 , 3 ); a = 2 b = 3 18


Αρχικοποίηση υποκλάσεων (πολλαπλοί κατασκευαστές) class Parent { int a; int b; Parent ( ) { a = 0; b = 0; } Parent(int alpha, int beta) { a = alpha; b = beta; } } class Child extends Parent { Child( ) { } Child (int alpha, int beta) { super (alpha, beta); } } Child my. Child = new Child(); Καλεί τον default constructor του Parent, άρα α=b=0 Child my. Child = new Child ( 1 , 2 ); a = 1, b = 2 20






Παραδείγματα private final int a = 5; a = 6 ; ΛΑΘΟΣ n n class A { public final void foo(); } class B extends A { public void foo( ) {. . . } ΛΑΘΟΣ } final class A { …. . } class B extends A { …} ΛΑΘΟΣ n 26


Παράδειγμα abstract public class Shape { abstract public void Draw ( ); } n public class Circle extends Shape { public void Draw ( ) { κώδικας σχεδίασης κύκλου} } n public class Rectangle extends Shape { public void Draw ( ) { κώδικας σχεδίασης ορθογωνίου} } n 28


Παράδειγμα class my. Class { public static int a = 1; } my. Class first = new my. Class ( ); my. Class second = new my. Class ( ); first. a = 2 ; Η μεταβλητή a παίρνει την τιμή 2 και στα δύο αντικείμενα δηλ. ισχύει first. a = 2 KAI second. a = 2 30


Interfaces - Παράδειγμα public interface my. Interface { public void foo( ); public void foo 2( String str ); } public class Test extends some. Parent. Class implements my. Interface { public void foo ( ) { Function code here…} public void foo 2 ( String str ) { Function code here…} } 32


Παράδειγμα Folder 1 Folder 2 A 21. java A 22. java A 11. java A 12. java A 11. java: package Folder 1; class A 11 { Class Implementation…. . } A 12. java: package Folder 1; class A 12 { class implementation……} A 21. java: package Folder 2; class A 21 { Class implementation} A 22. java: package Folder 2; import Folder 1. A 11; class A 22 { Class implementation} 34
class Tdate public void Tdate int int void
declare bonus Student float declare bonus Employee void
CLASS 5 int myabsint int rectint int int
stack void testint int int main int A
void polygonint a int b int c int
void mulint a int b int c int
public void draw Rectint x int y int
void main int a32767 printfd a void main
void insert First node ptrhead int input void
C overload swap void swapint int void swapdouble
2 stringarray 1 c void main void int
class AVLNode public int dann public int balance
class Base int i public void f osnovna
class X int m public X void m5
class A int x y public void f
class X int m public X void m5
length public length public void print Arrayint int
class Clock int hours int minutes int seconds
Education Salary Credit Administrative Salary Advancement through Professional
Whats New Salary Increases FY 18 and Salary
Salary Head Essential norms of salary income Relationship
Salary Floor Division of Retirement and Benefits Salary
National Institutes of Health Salary Cap Salary Cap
Salary Formulas Presented to the Faculty Salary and
MCCC DAY UNIT SALARY GRID SALARY GRID SYSTEM
Wages and Salary Administration Meaning of Wages Salary
of your salary entitlements what is salary packaging
MEANING OF SALARY Salary includes section 171 Wages
Education Salary Credit Administrative Salary Advancement through Professional
of your salary entitlements what is salary packaging
Salary Analytics Integrated salary reporting system raportyplacowe pl
Differences in accounting Topic Salary Overview Salary Differences
Bonus Bonus Definition of work using calculus Infinitesimal
MARKETING PLAN Retail Profit Sponsorship Bonus Group Bonus