LOGO inheritance 26112563 Nerissa Onkhum LOGO 26112563 LOGO
- Slides: 70
LOGO การสบทอด (inheritance( 26/11/2563 Nerissa Onkhum
LOGO ���� 26/11/2563
LOGO ������ (Polymorphism ( 26/11/2563
LOGO ������� 26/11/2563
������ public enum Color{ Red, Green, Blue } public class Shape { private Color color; public Shape} () color = Color. Red ; { public double get. Area } () return 0 ; { public void set. Color(Color c } ( color = c; { public Color get. Color } () return color ; {
�������� public class Test. Shape { public static void main(String[] args} ( Shape s 1 = new Shape; () System. out. println(s 1. get. Color; (() System. out. println(s 1. get. Area; (() Shape s 2 = new Shape; () s 2. set. Color(Color. Blue; ( System. out. println(s 2. get. Color; (() System. out. println(s 2. get. Area; (() } } 26/11/2563
�������� class Rectangle extends Shape} private double width; private double height; public Rectangle(int w, int h}( width = w ; height = h; { public double get. Width}() return width; { public double get. Hight}() //��������� } }
�������� class Rectangle extends Shape} public double get. Area} () return width * height; { … { 26/11/2563
�������� class Rectangle extends Shape} public String to. String}() String str = “Rectangle; ” str += “color = “ +get. Color; () str += “width = “ +width; str += “height = “ +height; str += “area = “ +get. Area; () return str; { {
�������� class Test. Shape 1 { public static void main(String[] args) { Rectangle r = new Rectangle(3, 4); System. out. println(r. to. String()); } } 26/11/2563
LOGO ���� Object 26/11/2563
เมธอด to. String () public class Rectangle extends Shape {. . . public String to. String() { String str = "Rectangle"; str += " color=" + get. Color(); str += " width=" + width; str += " height=" + height; str += " area=" + get. Area(); return str; } } 26/11/2563
����� equals() public boolean equals(Object other. Object) { if (other. Object instanceof Rectangle) { Rectangle other. Rect = (Rectangle) other. Object; boolean equal. Width = width == other. Rect. width; boolean equal. Height = height == other. Rect. height; return equal. Width && equal. Height; { return false; { 26/11/2563
����� hash. Code() v ������������������������ public int hash. Code() { return (int) (width + height * 17); } 26/11/2563
����� clone() ��������������� public Object clone() { Rectangle clone = new Rectangle(width, height); return clone; } 26/11/2563
��������� �� Object public class Test. Rectangle 3 { public static void main(String[] args} ( Rectangle r 1 = new Rectangle(2, 5; ( System. out. println(r 1. hash. Code; (() Rectangle r 2 = new Rectangle(5, 2; ( System. out. println(r 1. equals)r 2; (( Rectangle r 3 = (Rectangle) r 1. clone; () System. out. println(r 1. equals(r 3; (( { { 26/11/2563
�������� Public class Rectangle extends Shape{ public Rectangle(double w, double h){ …. } } public class Square extends Rectangle { public Square( double w) { super(w, w); ������ } �������. . . �� Rectangle }
คลาสสเหลยมจตรส public class Square extends Rectangle { public Square(double w){ super(w, w) } public String to. String() { String str = "Rectangle"; str += " color=" + get. Color(); str += " width=" + get. Width(); str += " area=" + get. Area(); return str; } } 26/11/2563 ������ Rectangle ����� Shape ���������� Rectangle
LOGO ������� 26/11/2563
������ v ����������� public final class Square ����� Public class Square. Child extends Square 26/11/2563 ������
final class vคลาสในแพจเกจ java. lang*. § Final class เชน • String. Buffer • Math • System • Integer • Double
����� v����������� public class Shape} public final Color get. Color} () return color; {. . . { public class Rectangle extends Shape} public Color get. Color(){ return Color. Blue; } } 26/11/2563
LOGO ������ protected 26/11/2563
����� public class Circle extends Shape} protected double radius; public Circle(double r} ( radius = r; { public double get. Radius} () return radius; { public double get. Area}() return Math. PI* radius; { {
��������� public class Ring 1 extends Circle} public double get. Area} () double outer. Area = Math. PI * radius ; double inner. Area = Math. PI * inner. Radius ; return outer. Area - inner. Area; {. . . { 26/11/2563
��������� public class Ring 2 extends Circle} public double get. Area} () double outer. Area = super. get. Area; () double inner. Area = Math. PI * inner. Radius ; return outer. Area - inner. Area; {. . . { 26/11/2563
LOGO ������� (abstract class( 26/11/2563
����� abstract class v ������������ Shape s = new Shape; () v ������������ Shape s; s = new Rectangle(3, 2; ( s = new Square(5; ( 26/11/2563
������� public class Test. Polymorphism { public static void main(String[] args} ( Shape shape; shape = new Rectangle(10, 20; ( System. out. println(shape. get. Area; (() shape = new Circle(10; ( System. out. println(shape. get. Area; (() { { 26/11/2563
������� public class Shape. Array} public static double sum. Area(Shape[] shapes} ( double sum = 0; for( Shape s : shapes} ( sum += s. get. Area; () { return sum; { { 26/11/2563
������� Shape[] s = new Shape[3]; s[0] = new Triangle(10); s[1] = new Rectangle(10, 20); s[2] = new Pentagon(20); double d = Shape. Array. sum. Area(s); 26/11/2563
LOGO ������� 26/11/2563
LOGO ���� 26/11/2563
LOGO 26/11/2563
- Msc nerissa current position
- Gratiano character sketch
- Nerissa ang
- Inheritance logo
- Encapsulation inheritance polymorphism
- Mendel
- Solidity multiple inheritance
- Chapter 11 section 1 basic patterns of human inheritance
- Section 2 complex patterns of inheritance
- Genes is the study of heredity and variation
- Contoh program inheritance java
- Probability laws govern mendelian inheritance
- Sexlinked inheritance
- Polygenic inheritance
- Advantages and disadvantages of inheritance in java
- The holy spirit is a deposit guaranteeing our inheritance
- Object diagram java
- Inheritance pattern of sickle cell anemia
- A gene locus is
- Inheritance
- Modern genetics human inheritance answer key
- The cellular basis of reproduction and inheritance
- Linked genes and unlinked genes
- Introduction to inheritance
- Inheritance in c
- Example of sex linked pedigree
- Perbedaan inheritance dan polymorphism
- The pedigree below traces the inheritance of alkaptonuria
- Inheritance presentation
- Type of dominance in genetics
- Inheritance types in java
- Mr men inheritance
- Sean blaine
- The chromosomal basis of inheritance chapter 15
- Perservefamily status
- Hair-on-end appearance thalassemia
- Mendelian pattern of inheritance
- Inheritance tax valencia region spain
- Contoh single inheritance
- Ppt molecular basis of inheritance
- Non mendelian inheritance
- The pedigree below traces the inheritance of alkaptonuria
- Abstraction encapsulation inheritance polymorphism
- Inheritance in r
- Recessive trait
- Encapsulation inheritance polymorphism
- Characteristic of learners
- Mosaicism
- Chromosomal theory of inheritance
- Savings account java
- Qualitative traits vs quantitative traits
- Chromosome theory of inheritance
- Private inheritance
- Interface calculator public int add(int a int b) class test
- What is inheritance
- Epistatic inheritance
- Priority inheritance
- X linked recessive punnett square
- Inheritance means
- Java definition
- Complete dominance pattern of inheritance
- Apa itu method
- Carl jung theory
- Definition of incomplete dominance
- C++ advantages
- Inheritance timeline
- Inheritance vs heredity
- Inheritance vs heritability
- Inheritance allows
- What are mendelian traits
- Family resemblance test