Chap 4

  • December 2019
  • PDF

This document was uploaded by user and they confirmed that they have the permission to share it. If you are author or own the copyright of this book, please report to us by using this DMCA report form. Report DMCA


Overview

Download & View Chap 4 as PDF for free.

More details

  • Words: 2,349
  • Pages: 24


 & &#'')*

 "78/4'9"+ "%8 :;"1'(<""='4#,11'(1'(-,f"'!:(<1(0IA6//:.K /LA+'$@'0 40'$C/6='"A$'0DH'6F %B9I29"1'(-,f"'!:(<1(0IA6//:.KIH" #'& //:.K 3#,1?  <#0L/5  <""='1'(:(1')='"A$'05,61#H'@!5$9I2>'?'.'@' /LA+'$ 3#,1?5H"C/6!:(<1(0IA6//:.K <""='#'& 9%B I29"1'(.='#/6C2/1='4"5C/6 !:(<1(0IA6//:.K <#9"&H@" 2'$C/6+ .:;"1'(<""='C,8"D/"1'(-,f"'!:(<1(0 !5$9I24#,11'(IA6//:.K

&  '("' )*  >'?'.'@':;">'?'/0-A@D/(E %B9I24#,11'(1'(-,f"'!:(<1(0IA6//:.K %B (%$1$H/@H':;">'?'/0-A@D/(E<++ [[  1'(-,f"'!:(<1(0IA6//:.K.:;" C+@"1'(1'(@A('4E:]n4'!5$1'(.='#/6:]n4'@H':(1/+G:52@$//:.K95+2'6 <#[email protected] C%$"942/$M9H "(M:<++C/6!:(<1(0/0-A@D/(E !:(<1(0IA6//:.K.0%='"A$'0 &%B =',n &/6='7///:.KdyX<##'&X

& *  //:.K7/&A6B DH'6F %B0%/$MH9"I%@DA :(.='@,"<+H6G52:;"&/6:(> 7/ PQ &AB6 %B :;"(M:L((0d7/&AB6 %B :;"@,D*3<#.,+D2/6G52/' AIH"",1)S1?'9+ #6 +%$":'11'<#(*:;"D2" Q &AB6 %B :;""'0L((0 d 7/&AB6 %BG0H&'0'(*.,+D2/6G52/' AIH" <"" ('$I7B/@AI'+,nI%6A"˜'1<#D'('6 %B$@+A":;"D2" //:.KDH'6F.:(1/+G:52@$3#,1?  d  <#-oDA1((0 d 3#,1?1K7/C2/0M#C/6//:.K&H@"-oDA1((04(7/(%$1@H'0L/5V7/ &AB6 %B   //:.K&'0'(*1( ='G52 RSB69"!:(<1(0IA6//:.K1K7/='&,6B 9"1'( ='6'" !:(<1(0IA6//:.K.:(1 /+52@$//:.KDH'6F4#'$//:.K RSB6
    

    





0%3#,1?DH'6F %B :;"C2/0M#C/6//:.K <#!:(<1(0&'0'(*.,51'(1,+C2/0M#4#H'"%8G52 !5$1'((%$19I20L/5DH'6F D,@/$H'6C/6//:.K x ",1)S1?'   

/'..:(1/+G:52@$3#,1?IH"(4,&I7B/<#1(5|#%$B  <#/'..0%0L/5IH"#6 +%$"&/+<#5A"

x (*$"DE   

/'..:(1/+G:52@$3#,1?IH"$%B42/(3H"<#&% <#/'..0%0L/5IH"#7B/" %B4$35<##%$8 @

x &3",C  /'..:(1/+G:52@$3#,1?IH"I7B/-,"L3E<#&%    <#/'..0%0L/5IH"4H'#'"<#1(5A14'6 D,@/$H'6C/6!:(<1(0IA6//:.K/'.$1D,@/$H'6C/6!:(<1(0(++.,51'(+,nI%6A" ˜'1C/6L"''( RSB6/'.:(1/+G:52@$//:.KDH'6F/' A IH" +,nI% NXX  #M12'    (7B/6/ % /K0 Nk <#('$1'(  X //:.KI"A5+,nI%/'..0% C2/0M#>'$9"DH'6F/' A IH" #C %B+n , I% I7B/.2'C/6+,nI% @," %B :ƒ5+,nI% <#$/56A"64#7/ :;"D2"//:.KI"A5+,nI%/'..0%0L/5DH'6F/' A IH"˜'1*/"<#1'(!/"6A":;"D2"

&  # !5$ @,B G:!:(<1(0IA6//:.K
 

 !"!#$%&'(&" )&*'+," !"!#$%-(./01#2'.2'3 4'(#'51(+,6



  ,! D,@/$H'6C/6//:.K<##'& 

&"  /@#'@  3#,1?C/6//:.K7/C2/0M# %B 1K+/$M9H "//:.K RSB6.<+H6//1:;"&/6:(>  7/D,@<:( d<#H'6 %BX!5$ %B 3#,1? %B:;"D,@<:(.&'0'(*:#%B$" H'G52 &H@"3#,1? %B:;"H'6 %B.G0H&'0'(*:#%B$"H'G52 (M: %B uQ <&56D,@/$H'6C/6 //:.Ks1,s2<#s3 %B :;"//:.KC/6#'&StudentRSB60%3#,1?C/6//:.K %B :;"(4,&I7B/<#<""|#%$B &&0 %BDH'61,"!5$1='4"59"H'C/6D,@<:( id, name<# gpaD'0#='5,+

  ,!$D,@/$H'63#,1?C/6//:.K     

    





!:(<1(0IA6//:.KG521='4"5"A$'03#,1?/%1:(> 4"SB6 %B (%$1@H' 3#,1?C/6#'& X V   RSB6.:;"3#,1? %B 31//:.K9I2(@H 01," /' A IH" #'& Student /'.1='4"59420%3#,1?C/6#'& %B:;"H'6 %B %BI7B/ MIN_GPA -7B/1K+H'<""|#%B$&&0C,"8 DB='C/6",1)S1?' 31" ,86"%8",1)S1?' 31".D2/60%H' <""|#%B$&&0&M61@H'<""|#%B$&&0C,8"DB=' 1'(1K+3#,1? %B407/"1,"IH""%8*'2 1='4"5942:;"3#,1?C/6//:.K. ='942&A8":#7/6"78/ 9%B "4"H@$@'0.=' 5,6<&56942 4K"9"(M: %B uQc 1
 

 !"!#$%&'(&" )&*'+," !"!#$%-(./01#2'.2'3 4'(#'51(+,6





EF3#,1?C/6#'&   ,!%3#,1?MIN_GPARSB6:;"3#,1?C/6//:.K<##'&

&&  G0  0L/5:;"@AL%1'(4(7/1'(1( =' %B"A$'0/$MH9"#'&4(7///:.K-7B/9I29"1'(.,51'( 1,+3#,1?C/6//:.K4(7/3#,1?C/6#'&/' AIH" //:.KI"A5+,nI%6A"˜'1/'. -7B/1K+$/56A"64#7/ /%B $MH9"+,nI% <#/'.0%0L/5 0%3#,1? balance deposit()-7B/:;"@AL%1'(9"1'(˜'16A"9421,+//:.K 9"0L/5.0%='&,B6-7B/.,51'(1,+ @AL%1'(˜'16A"<#. ='1'(:(,+:#%B$"H'C/63#,1? balance ('&'0'(* :(%$+ %$+0L/5G521+, J]61EI",  XV 4(7/\ d   C/6!:(<1(0IA61(+@"1'( 1'(C%$"!:(<1(0IA6//:.K.1='4"5942//:.KDH'6F&7B/&'(1," !5$1'(WH'" CH'@&'(  (4@H'6//:.K %B :;"WM&2 H6 \V  1,+//:.K %B :;"WM2(,+ hX  !5$1'((%$19I20L/5/' A IH"(M: %B uQu<&56D,@/$H'6C/61'(&H6CH'@&'(.'1//:.K objA %B:;"WM&2 H6-7B/(%$11'( ='6'"C/60L/5method4() C/6//:.KobjB %B:;"WM2(+, 1'( &H6CH'@&'((4@H'61,"/'.0%1'(&H6C2/0M#.'1 objAWH'"G:$,6 objB!5$WH'" '6  

    

    





C/60L/5D,@/$H'6IH" H'P <#9"(M: %B uQu<#WM2(+, 1K/'.&H6H'1#,+      0'$,6WM2&6H

  ,!,D,@/$H'6C/61'(&H6CH'@&'((4@H'6//:.K

& '+("' )* (0+D)  & ''f # !:(<1(0>'?'.'@'
#'&/$H'6"2/$4"SB6#'&

[modifier] class ClassName { [class member] }

 !5$ %B x

modifier 7/%$E@A(E5 w  V C/6>'?'.'@'

9%B I2:;" XX V IH" public 4(7//LA+'$3&0+,DA/7B"FC/6#'& IH" abstract <# finalRSB6:;"67B/"GC-AB0DA0

x

class7/%$E @A(E5C/6>'?'.'@'-7B/(+3@H':;"1'(:(1')#'&

x

ClassName 7/I7B/C/6#'&

%B:;"I7B/ V  95F %B&/5#2/61,+1ˆ1'(D,86

I7B/

 

 !"!#$%&'(&" )&*'+," !"!#$%-(./01#2'.2'3 4'(#'51(+,6





x classmember7/0L/54(7/3#,1?C/6#'& D,@/$H'61'(:(1')#'&Student&'0'(* ='G525,6"%8 public class Student {   }

& ''f /@#'@ 3#,1?C/6//:.K7/D,@<:(4(7/H'6 %BRSB6:(1')>'$9"//:.K (M:<++1'(:(1')5,6"%8

!5$0%

[modifier] dataType attributeName; 

!5$ %B x

modifier

7/%$E@A(E5C/6>'?'.'@' %B/LA+'$3&0+,DADH'6FC/6D,@<:(4(7/ H'6 %B/' A IH" public, private, static, final <# transient:;"D2"

x

dataType7/I"A5C2/0M#RSB6/'.:;"I"A5C2/0M#<++-78"l'"4(7/I"A5C2/0M#<++

/2'6/A6 %.1#H'@*S69"+ DH/G: x

attributeName 7/I7B/C/63#,1?

%B:;"I7B/ V 95FRSB6&/5#2/6

1,+1ˆ1'(D,86I7B/ D,@/$H'61'(:(1')3#,1? id, name <# String<#double9"#'&Student&'0'(* ='G525,6"%8    public class Student {

gpa

RSB60%I"A5C2/0M#:;"

public String id; public String name; public double gpa; }

&" ''f G0 >'?'.'@'1='4"5(M:<++C/61'(:(1')0L/5 %B/$MH9"#'&G@25,6"%8       

    





[modifier] return_type methodName([arguments]) { [method_body] } 

!5$ %B 7/%$E@A(E5C/6>'?'.'@' %B :;" XX V  IH" public 4(7/ private 4(7//LA+'$3&0+,DA/7B"FC/60L/5IH" abstract 4(7/ static:;"D2"

x

modifier

x

return_type

x

methodName7/I7B/C/60L/5

7/I"A5C2/0M#C/6H' %B&6H 1#,+4#,6.'1&(K.&A8"1'( ='6'"C/6 ='&,B69"0L/5"%8 !5$I"A5C2/0M#C/6H' %B&6H 1#,+/'.:;"I"A5C2/0M#<++-78"l'" 4(7/I"A5C2/0M#<++/2'6/A6 9"1(% %BG0H0%1'(&H6H'95F1#,+.D2/6(+3I"A5C2/0M# :;"void %B:;"I7B/V 95FRSB6&/5#2/61,+1ˆ1'(

D,86I7B/ x

arguments

7/D,@<:( %B9I29"1'((,+C2/0M# %B//:.K&H60'942 0'11@H'4"SB6D,@<:(4(7/G0H0% #$1KG52CS8"/$MH1+, 1'(1='4"50L/5

!5$/'.0%

x method_body7/='&,B6DH'6FC/6>'?'.'@' %B/$M9H "0L/5  !:(<1(0 %BuQP<&56D,@/$H'6!:(<1(0>'?'.'@' %B:(1')#'&\tudent!5$0% 3#,1?7/ id, name, gpa <# MIN_GPA <#0%0L/57/ setID(), setName(), setGPA()<#showDetails()         

 

 !"!#$%&'(&" )&*'+," !"!#$%-(./01#2'.2'3 4'(#'51(+,6

 ("'  ,! #'&Student public class Student { public String id; public String name; public double gpa; public static final double MIN_GPA = 2.00; public void setID(String ID) { id = ID; } public void setName(String n) { name = n; } public void setGPA(double GPA) { gpa = GPA; } public void showDetails() { System.out.println("ID: "+id); System.out.println("Name: "+name); System.out.println("GPA: "+gpa); }

    }

 G0main() !:(<1(0>'?'.'@' %B :;"!:(<1(0.'@':($31DE NX.(A0B D2"1'( ='6'"9"#'& 0%B % 0L/5main()!5$0%(M:<++C/60L/55,6"%8 public static void main (String args[]) { [method_body] }

&& ''f"#*  //:.K 31//:.K9"!:(<1(0>'?'.'@'.D2/60%='&,B6:(1')-7B/(+3@H'//:.K ",8":;"//:.KC/6#'&95!5$0%(M:<++5,6"%8 [modifier] ClassName objectName; 

!5$ %B

    

    





x

modifier7/%$E@A(E5

%B/LA+'$3&0+,DDA H'6FC/6//:.K

x

ClassName7/I7B/C/6#'&

x

objectName

7/I7B/C/6//:.K %B :;"I7B/ V  95FRSB6&/5#2/61,+1Z

1'(D,86I7B/   D,@/$H'6IH"='&,B6 Student s1;       :;"='&,B6:(1')//:.Ks1 942:;"//:.KC/6#'&Student ,86"%8#'& %B(+3 9"='&,6B :(1')//:.K.D2/6:;"#'& %B0%1'("A$'0G@2<#2@ 1#H'@7/.D2/60%#'& Student %B"A$'0G@2<#2@  ='&,B69"1'(:(1')//:.KG0HG52:;"='&,B6 %B9I29"1'(&(2'6//:.K='&,6B %B9I29"1'( &(2'6//:.K.0%(M:<++5,6"%8 

 



objectName = new ClassName([arguments]);

  !5$ %B  7/I7B/C/6//:.K

x

objectName

x

new7/%$E @A(E5C/6>'?'.'@'-7B/9I29"1'(&(2'6//:.K

x

ClassName7/I7B/C/6#'&

7/H' %BD2/61'(&H6WH'"9"1'((%$10L/59"1'(&(2'6//:.KRSB6 /'.0%4(7/G0H0%1KG52 1'(&(2'6//:.K!5$(%$19I2='&,B6 new "%8.:;"1'((%$19I20L/59"1'(&(2'6 //:.K %B (%$1@H' X X  C/6#'&",8"F RSB6.0%1'(/LA+'$1'( ='6'"C/6 X X  9"+ %B t D,@/$H'6='&,6B 9"1'(&(2'6//:.Ks1 ='G525,6"%8     s1 = new Student(); "/1.'1"%8='&,6B 9"1'(:(1')<#&(2'6//:.K&'0'(* .%B (@0:;"='&,6B 5%$@1," G52!5$0%(M:<++='&,6B 5,6"%8 x

arguments



[modifier] ClassName objectName = new className([arguments]);

 

 !"!#$%&'(&" )&*'+," !"!#$%-(./01#2'.2'3 4'(#'51(+,6

 

/' AIH"    Student

s1 = new Student();



&- '+'D) )'*

&0'IA1C/6//:.K:(1/+52@$3#,1?<#0L/5 1'((%$19I2&0'IA1C/6 //:.K ='G52!5$1'(9I2(7B/640'$.35 Q 1#H'@7/3#,1?C/6//:.K&'0'(*(%$19I2 !5$0%(:M <++5,6"%8 

objectName.attributeName;



!5$ %B x

objectName

7/I7B/C/6//:.K &%B (2'6CS8"

x attributeName 7/I7B/C/63#,1?C/6//:.K",8" "/1.'1"%8('&'0'(* .%B &H6CH'@&'(G:$,6//:.K>'$4#,6.'1 %B0%1'(&(2'6//:.K CS8"0'G52!5$1'((%$19I20L/5C/6//:.K",8"(M:<++='&,6B 9"1'((%$19I20L/50%5,6"%8 objectName.methodName([arguments]); 

!5$ %B x

objectName

7/I7B/C/6//:.K &%B (2'6CS8"

x

methodName

7/I7B/C/60L/5C/6//:.K",8"

7/H' %BD2/61'(&H6WH'"G:9421,+0L/5C/6//:.K",8" !5$ %B .D2/60%I"A5C2/0M#<#.='"@"    942&/5#2/61,+ %B:(1')9"0L/5 C/6//:.K",8" D,@/$H'6IH"='&,B6     s1.setName(“Thana”); :;"1'((%$19I20L/5 setName() C/6//:.K s1 RSB6:;"//:.KC/6#'& Student !5$.&H6WH'"    I"A5 String %B0%H':;"C2/@'0 Thana 9421,+ 0L/55,61#H'@ !:(<1(0 %B uQ <&56D,@/$H'6!:(<1(0C/6#'& Sample %B0% 0L/5 main()/$MH !5$!:(<1(0"%. 8 &(2'6//:.KC/6#'& Student CS8"0'&'0//:.K7/ //:.K s1, s2 <# s3 .'1",8". ='1'((%$10L/5 setName() -7B/1='4"5H'942 x

arguments

    

    





1='4"5H'9421,+3#,1? //:.K5,6<&569"(M: %BuQt

name

C/6//:.K
("'  ,!$#'&Sample

   

public class Sample { public static void main(String args[]) { Student s1 = new Student(); Student s2 = new Student(); Student s3 = new Student(); s1.setID("1234"); s1.setName("Thana"); s1.setGPA(3.25); s2.setID("1122"); s2.setName("Somchai"); s2.setGPA(2.90); s3.setID("2211"); s3.setName("Somsri"); s3.setGPA(3.00); } }





  ,!-W##,-LEC/6!:(<1(0 %BuQ

 

 !"!#$%&'(&" )&*'+," !"!#$%-(./01#2'.2'3 4'(#'51(+,6



&" /@#'@01("' )*    !:(<1(0IA6//:.K .0%3#,1?5H"/$MH&'0:(1'(7/ 1'(4H/4320 }X 1'(&7+ /5O X<#1'(0%G524#'$(M:<++  

&" '&1&/  4#,11'( %B&=',n:(1'(4"SB6C/61'(C%$"!:(<1(0IA6//:.K7/1'(4H/4320  RSB6 3#,1?C/6//:.K.*M14H/4320/$MH>'$9" -7B/G0H942//:.K/7B"F&'0'(*C2'*S6C2/0M# %B :;"3#,1?G52!5$D(6 1'(.(%$19I23#,1?C/6//:.K. ='G52!5$1'((%$1WH'" 0L/5 H'",8"5,6<&569"(M: %B uQ…

  ,!.4#,11'(C/61'(4H/4320   //:.K'?'.'@'1K7/3#,1?4(7/0L/5 *%B 1M :(1')9420%XXV  :;" public &='4(,+&H@" %B :;"  7/&H@"C/6//:.K %BG0H&'0'(*C2'*S6G52 .'1>'$"/1 //:.K/7B"F.G0H&'0'(*4K"&H@" %B :;"C/6//:.KG52 9" >'?'.'@'1K7/3#,1?4(7/0L/5 %B*M1:(1')9420%XXV :;"private   1'(C%$"!:(<1(0IA6//:.K!5$9I24#,11'(C/61'(4H/4320 &'0'(* ='G52!5$ 1='4"59423#,1?C/6//:.K0%XXV :;"private <#1='4"59420L/5 %B &'0'(*(%$1.'1//:.K>'$"/1G520% XX V  :;" public 5,6<&569"D,@/$H'6 !:(<1(0 %BuQc



    

    





("'  ,!%1'(9I24#,11'(C/61'(4H/4320 

public class Student { private String id; private String name; private double gpa;  private static final double MIN_GPA = 2.00;



public void setID(String ID) {  id = ID; }  n) { public void setName(String name = n;  } public void setGPA(double  GPA) { gpa = GPA; }  public void showDetails() {  "+id); System.out.println("ID: System.out.println("Name: "+name);  System.out.println("GPA: "+gpa); }



}

 C2/5%C/61'(4H/43207/ x 1'(RH/"(2"C2/0M#O UV ='942//:.K&'0'(*DA5DH/1,+//:.K >'$"/1WH'"0L/5 %B :;"&H@"C/6  X  H'",8" RS6B *2'0%1'(:#%$B "<:#6 3#,1?4(7/0L/5 %B/$MH>'$9"//:.K 1K.G0H0%W#1( +95FDH///:.K >'$"/1 %B (%$19I2 x @'0:;"!05M# kV     1'(-,f"'!:(<1(0IA6//:.K.&'0'(* 1='4"5942//:.K'$9"//:.K4"SB61K.G0H0%W#1( +DH///:.K/7B"   (7B/6! (),- E :;"D,@/$H'64"SB6 C/61'(<&563#,1?5H"52'"1'(4H/4320C/6 //:.K &H@" %B :;"  X 1K7/:3™0C/6! (),- E %BW9M2 I2&'0'(*DA5DH/1,+(7B/6G52 &='4(,+ (++/A#K1 (/"A1&E %B/$MH9"(7B/6! (),- E7/&H@" %B :;"  RSB6WM29I2G0H&'0'(* 0/64K"<#G0H.=':;"D2/6C2'9.1'( ='6'"C/6(++5,61#H'@ <#4'1(++/A#K1 (/"A1&E >'$9":#%B$"<:#6G: WM29I2$6, &'0'(* .%B DA5DH/1,+(7B/6G52!5$9I2:3™0 %B :;"&H@"  X IH"5A0  

 !"!#$%&'(&" )&*'+," !"!#$%-(./01#2'.2'3 4'(#'51(+,6



&" '0 3#,1?5H":(1'(4"SB6C/61'(!:(<1(0IA6//:.K7/ @'0&'0'(* %B. "='/'!:(<1(0 %B//1<++G@2<#2@0'9I2940HG52 RS6B &='4(,+!:(<1(0IA61(+@"1'(. ='G52 !5$1'(1='4"5='&,B6 %BD2/69I2+/H $G@29"!:(<1(0$H/$J]61EI,B"4(7/ XV RSB6.0%@'0 R,+R2/"9"1'(//1<++-7B/942G52!:(<1(0$H/$ %B 40'&0 ='9421'("='!:(<1(00'9I2940H C/6!:(<1(0IA61(+@"1'(H/"C2'6.:;"G:G52$'11@H' <#07B/!:(<1(00%@'0R,+R2/" CS8" 1'("='!:(<1(00'9I2940H1K:;"G:G52$'1CS8" "7B/6.'1('G0H&'0'(*//1<++!:(<1(0 (/+#30:]n4' 6,8 405G@2#H@64"2'G52 @AL%1'("='!:(<1(00'9I2940HC/6!:(<1(0IA6//:.K.9I24#,11'(C/61'(&7+ /5 RSB6:;"1'("A$'0#'&940H.'1(M:<++C/6#'& %B0%/$MH<#2@ !5$#'&940H."='3#,1? <#0L/5C/6#'&5A00'9I2G52 !5$ ,B@G:#'&DH'6F 0%B %/$MH.0%!(6&(2'6 0%B %@'0&,0-,"LE 1,"D'0#='5,+I,8" ('&'0'(* %B.//1<++!:(<1(0IA6//:.K-7B/&(2'6#'& %B:;"#'& <++ @,B G:  ŠV X RSB6.0%3#,1?<#0L/5-7B/942#'&/7B"F %B :;"#'& |-' XX X &7+ /5G52 #'& %B :;"#'&<++ @,B G:.(%$1@H':;"   X 4(7/   X &H@"#'& %B:;"#'&|-' %B&+7 /50'.(%$1@H':;"  dX 4(7/ XVX (M: %B uQv <&56D,@/$H'6C/6#'& 9%B I24#,11'(C/61'(&7+ /5 D,@/$H'6"%.8 0%#'& Student :;"#'&<++ ,B@G: <#0%#'& GradStudent, PartTimeStudent <# FullTimeStudent &7+ /50'.'1#'& Student <##'& PhDStudent . &7+ /50'.'1#'& GradStudent /%1I,8"4"SB6 1'(&7+ /5.0%W#9423#,1?<# 0L/5C/6 \  X &7+ /5G:$,6 \ dX D,@/$H'6IH" *2'#'& Student 9"(M: %B uQv 0%3#,1? id, name, gpa <# MIN_GPA <#0%0L/5 setID(), setName(), setGPA() <# showDetails() #'& GradStudent` PartTimeStudent <# FullTimeStudent  1K.&7+ /53#,1?<#0L/5 4#H'",8"0'52@$"/1.'1"%8 #'& PhDStudent %B&7+ /50'.'1#'& GradStudent 1K .G52(,+3#,1?<#0L/5 %B&7+ /50'.'1#'&Student %B:;"  XC/6#'& GradStudent52@$ 

    

    





  ,!3D,@/$H'6C/6#'& %B9I24#,11'(C/61'(&7+ /5    C2/5%C/61'(&7+ /57/ @'0&'0'(*9"1'( .%B "='!:(<1(05A00'-,f"'-AB0DA0 940HG526H'$CS8"<#$,6IH@$ ='942!:(<1(0'?'.'@'.9I2%$E @A(E5 extends -7B/ (+31'(&7+ /5 !:(<1(0 %B uQu <&56D,@/$H'6C/6#'& 9%B I24#,11'(9"1'(&7+ /5D'0 G5/<1(0C/6#'&9"(M: %BuQv ("'  ,!,D,@/$H'61'(9I24#,11'(9"1'(&7+ /5        

public class PartTimeStudent extends Student { } public class FullTimeStudent extends Student { } public class GradStudent extends Student { private String thesisTitle; private String supervisor; public void setThesisTitle(String t) { thesisTitle = t; } public void setSupervisor(String s) { supervisor = s; } } public class PhDStudent extends GradStudent { public boolean passQualify; public boolean isPassQualify() { return passQualify; } }

 

 !"!#$%&'(&" )&*'+," !"!#$%-(./01#2'.2'3 4'(#'51(+,6



&"" ' ?0&#+ "   4#,11'(C/61'(0%G524#'$(M:<++7/ 3&0+,DCA /6!:(<1(0IA6//:.K %B&'0'(* D/+&"/6DH/CH'@&'( 0L/5 5%$@1,"52@$@AL%1'( D%B H'61," <#&'0'(*1='4"5//:.KG52 4#'$(M:<++ 4#,11'(C/61'(0%G524#'$(M:<++:;"4#,11'( %B&7+"7B/60'.'14#,11'(C/6 1'(&7+ /5 D,@/$H'6IH" (M: %B uQz 0%#'& Ball RSB6:;"   X C/6#'& SoccerBall<#TennisBall  

   ,!4D,@/$H'6C/6#'&Ball    #'&Ball/'.0%0L/5 throwBall() -7B/1='4"5-oDA1((01'(!$"#M1+/# RSB6 dX %BI7B/SoccerBall<#TennisBall/'.1='4"5@AL%1'(1'(!$"#M1+/#
    

='942!:(<1(0&'0'(*

    





("'  ,!-D,@/$H'61'(9I24#,11'(C/61'(0%G524#'$(M:<++  class Ball { public public void throwBall() { } } public class SoccerBall extends Ball { public void throwBall() { System.out.println(“Throwing soccerball”); } } public class TennisBall extends Ball { public void throwBall() { System.out.println(“Throwing tennisball”); } } public class TestBall { public static void main(String args[]) { Ball b1 = new Ball(); SoccerBall b2 = new SoccerBall(); Ball b3 = new SoccerBall(); } } 

&& TUVcVZYlXYZ`VU_m9U_P9_Z YV kV a  Yka :;">'?' %B9I2(M:1('JJƒ1-7B/.='#/6(++ R/JDE<@(E  Yka *M1-,f"'CS"8 -7B/.='#/6!:(<1(0IA6//:.K9"D2" )@((? %B Pssm RSB69" :]..3+," Yka G521#'$:;"0'D(l'" %B9I29"1'(.='#/6(++R/JDE<@(ED'0C2/1='4"5C/6 [k~ [dyX k ~    4",6&7/#H0"%.8 9I2&,n#,1?EC/6 Yka 9"1'(.='#/6 (++!:(<1(0DH'6F '?' %B0C% 2/1='4"5DH'6F0'1 5,6",8""78/4'9" + "%8.1#H'@*S6|-'&H@"DH'6F %B.=':;"DH/@'0C2'9. .%B 9I29"4",6&7/#H0"%8 H'",8" 

&& ?0"'  # G5/<1(0C/6#'&  :;"&,n#,1?E 9%B I2<&56#'&9"Yka!5$ G5/<1(0C/6#'&.:(1/+52@$&H@"DH'6F&'0&H@"7/ I7B/C/6#'& 3#,1?>'$9" #'& <#0L/5>'$9"#'& 5,6<&569"(M: %B uQs G5/<1(0C/6#'&.(+3C2/0M#DH'6F &='4(,+3#,1?>'$9"#'&7/ I7B/C/63#,1?  I"A5C2/0M#  &*'"1'(C2'*S6 XX V <#H'(AB0D2" &H@"0L/5>'$9"#'&.(+3*S6&*'"1'(C2'*S6 I7B/C/6  

 !"!#$%&'(&" )&*'+," !"!#$%-(./01#2'.2'3 4'(#'51(+,6

 0L/5 I"A5C2/0M#C/6    <#I"A5C2/0M#C/6H' &%B H61#,+ &='4(,+&*'"1'(C2'*S6 YkaG521='4"5&,n#,1?EDH'6FG@25,6"%8   j&='4(,+public   q&='4(,+private 



  ,!5D,@/$H'6Yka C/6#'& Student  G5/<1(0C/6#'&&'0'(* .%B <&56@'0&,0-,"LEC/6#'& %B0%1'(&7+ /51," !5$1'(9I2#M1)(:;"&,n#,1?E5,6<&56D,@/$H'69"(M: %B uQv "/1.'1"%8G5/<1(0C/6#'&$,6 &'0'(* .%B <&56@'0&,0-,"LE4(7/<&563&0+,DA/7B"FIH" <&56@H':;"#'&<++ interfaceG52/%152@$

&& ?0"' *

Yka  &'0'(* %B.<&569424K"G52@H'//:.K &%B (2'6CS8"0':;"//:.KC/6#'&95 <#0%H'C/63#,1?DH'6F/$H'6G( !5$9I2G5/<1(0C/6//:.K [dyX   %B :(1/+G:52@$&H@"DH'6F&/6&H@"7/ &H@" %B(+3I7B/C/6//:.K <#&H@" %B(+3H'C/6 3#,1?>'$9"//:.K 5,6D,@/$H'69"(M: %B uQPm RSB6:;"1'(<&56//:.K s1 <# s2 C/6#'& Student  .'1(M:.4K"G52@H'&,n#,1?E#M1)( %B:;"&2":.:;"1'((+3@H' //:.Ks1:;"//:.KC/6#'&Student

    

    





   ,! 6G5/<1(0C/6//:.Ks1<#s2C/6#'&Student

&- 'n("' 1'(-,f"'!:(<1(0/0-A@D/(E G0HG5240'$*S6-%$6<H1'(C%$"!:(<1(0='&,6B >'?'/0-A@D/(E>'?'95>'?'4"SB6
 



 !"!#$%&'(&" )&*'+," !"!#$%-(./01#2'.2'3 4'(#'51(+,6







   ,! C,8"D/"1'(-,f"'!:(<1(0

 C,8"D/"1'(@A('4E :;"1'()S1?'@'0:;"G:G52 d   V  C/6:]n4' %B D2/61'(-,f"'!:(<1(0 0% -,f"'!:(<1(0. ='1'(@A('4E:]n4'<#-A.'('@H'&'0'(* %B.-,f"'!:(<1(0/0-A@D/(E-7B/<12GC:]n4'G524(7/G0H W##,-LE %BG52.'1C,8"D/""%8 7/ C2/1='4"5D'0@'0D2/61'(  —   XX RSB6./LA+'$3#,1?C/6 !:(<1(0 !5$C2/1='4"5"%8.C%$"/$M9H "(M:<++DH'6F-7B/942WM29I2 WM:2 ZA+,DA6'" <#",1-,f"' !:(<1(0&'0'(*C2'9.G52 <#&'0'(* 5&/+!:(<1(0 %B-,f"'CS8"G52@H'*M1D2/6<#D(6D'0 @'0D2/61'(C/6WM29I24(7/G0H C,8"D/"1'(//1<++ .:;"1'( ='942C2/1='4"5D'0@'0D2/61'(:#%B$"G:/$M9H " (M:<++C/6('$#/%$5C/6!:(<1(0 %B.D2/6-,f"' RSB69"1'(//1<++!5$9I24#,11'(IA6 //:.K1K/'..G52G5/<1(0DH'6F9"(M:C/6 Yka -7B/ %B./LA+'$#'&<#//:.KDH'6F %B &/5#2/61,+C2/1='4"5D'0@'0D2/61'( C,8"D/"1'(C%$"!:(<1(0.:;"1'(C%$"!:(<1(0!5$9I2>'?'/0-A@D/(E>'?' 95>'?'4"SB6942:;"G:D'0!:(<1(0 %BG52//1<++G@2 RS6B 1'(#7/19I2>'?'/0-A@D/(E@( %B .D2/6&/5#2/61,+@AL%1'( G%B 52//1<++G@2 9"1(% C%B ,8"D/"1'(//1<++:;"1'(9I24#,11'( IA6//:.K1K@( .%B D2/69I2>'?'/0-A@D/(EIA6//:.KIH" >'?'.'@'9"1'(C%$" !:(<1(0 C,8"D/""%8.:;"C,8"D/" %BG0H$'1",1"7B/6.'1:;"1'(C%$"!:(<1(0D'0C2/1='4"5 %BG52.'11'(//1<++5,6",8"1'(-,f"'!:(<1(0 %B5%.D2/60%C,8"D/"1'(//1<++ %B5% -7B/942G52 !:(<1(0 %B*M1D2/6

    

    





C,8"D/"1'( 5&/+ .:;"C,8"D/" %B. 5&/+!:(<1(0 G%B 52-,f"'CS8" !5$/'.:;" 1'( 5&/+1'( ='6'"C/6!:(<1(0.'1C2/0M# %B"='0' 5&/+DH'6F <#D(@.&/+5M@H' !:(<1(0&'0'(* ='6'"G52*M1D2/6D'0C2/1='4"5D'0@'0D2/61'(4(7/G0H 1'( 5&/+ !:(<1(0IA6//:.K/'.:;"1'( 5&/+ #% $M"AD    4(7/1'( 5&/+!5$(@0  1'( 5&/+ %#$M"AD:;"1'( 5&/+1'( '= 6'"C/6
/& x !:(<1(0IA6//:.K.0%='"A$'0 &%B =',n&/6='7///:.K<##'& x //:.K7/&A6B DH'6F %B0%/$MH9"I%@DA :(.='@,".:(1/+G:52@$3#,1?<# 0L/5 x #'&:(%$+&07/"-A0-EC%$@C/6//:.K //:.K.*M1&(2'60'.'1#'& //:.K4#'$//:.K&'0'(**M1&(2'6.'1#'&4"SB6#'&G52 x 3#,1?C/6//:.K7/C2/0M# %B 1K+/$M9H "//:.K RSB6.<+H6//1:;"D,@<:( <#H'6 %B

 

 !"!#$%&'(&" )&*'+," !"!#$%-(./01#2'.2'3 4'(#'51(+,6

 x 3#,1?C/6#'&:;"3#,1? %B9I2(H@01,"C/6 31//:.K x 0L/57/@AL%1'(-7B/9I29"1'(.,51'(1,+3#,1?C/6//:.K4(7/3#,1? C/6#'& x >'?'.'@'0%"$A '09"1'(C%$"!:(<1(0IA6//:.K-7B/:(1')#'& 3#,1?0L/5<#//:.K x !:(<1(0IA6//:.K.0%3#,1?5H"/$MH&'0:(1'(7/ 1'(4H/4320 1'(&7+ /5<#1'(0%G524#'$(M:<++ x 1'(4H/43207/1'( %B9423#,1?*M14H/4320/$MH>'$9"0L/5 !5$1='4"5942 3#,1?0% ,558KK;=J/?/80:;" private<#1='4"59420L/50% ,558KK ;=J/?/80:;"public x C2/5%C/61'(4H/43207/1'(RH/"(2"C2/0M#<#@'0:;"!05M# x 1'(&7+ /57/1'( %B #'&940H&'0'(*"='/'3#,1?<#0L/5C/6#'& %B //1<++G@2<#2@0'9I2G52 x 1'(0%G524#'$(M:<++7/1'( %B1'= 4"59420%1'(D/+&"/6DH/0L/55%$@1,"52@$ @AL%1'( D%B H'61,"<#&'0'(*1='4"5//:.KG524#'$(M:<++ x YVkVa Yka:;">'?' B9% I2(M:1('JJƒ1-7B/.='#/6(++ R/JDE<@(E 9" %B"G%8 52<""='&,n#,1?EC/6Yka B&% =',n&/6/$H'67/G5/<1(0 C/6#'&<#G5/<1(0C/6//:.K x @,ˆ.,1(1'(-,f"'!:(<1(0.:(1/+G:52@$C,8"D/"DH'6F t C,8"D/"7/ C,8"D/"1'(@A('4E C,8"D/"1'(//1<++ C,8"D/"1'(C%$"!:(<1(0 C,8"D/" 1'( 5&/+<#C,8"D/"1'(+='(36(,1?'!:(<1(0

    

    





              

 

 !"!#$%&'(&" )&*'+," !"!#$%-(./01#2'.2'3 4'(#'51(+,6

Related Documents

Chap 4
June 2020 5
Chap 4
November 2019 22
Chap 4
December 2019 19
Chap 4
November 2019 16
Chap 4
November 2019 17
Chap 4
April 2020 15