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%i%/%?L>(B();
$B%/%i%9L>(B $B%$%s%9%?%s%9JQ?tL>(B = new $B%3%s%9%H%i%/%?L>(B();
new
$B1i;;;R$K$h$C$F:8JU$NJQ?t$KBeF~$5$l$F$$$k$3$H$K$J$j$^$9!#(B$B%3%s%9%H%i%/%?$H$O$J$s$@$m$&(B
void
$B%-!<%o!<%I$r;}$?$:La$jCM@k8@$b$J$$%a%=%C%I(B$B$G$9!#0z?t$N0[$J$k%3%s%9%H%i%/%?$rF1;~$KDj5A$9$k$3$H$b2DG=$G$9!#$3$l$r(B$B%*!<%P!<%m!<%I(B$B$H8F$S$^$9!#(Bjavac
$B$O!"<+F0E*$K!"(B$B0z?t$J$7$GFbMF$,6u(B$B$N%G%U%)%k%H!&%3%s%9%H%i%/%?$r!"@8@.$9$k%P%$%H%3!<%IFb$KKd$a9~$s$G$/$l$^$9!#0z?t$r$b$D%3%s%9%H%i%/%?$r<+J,$G:n$k$H!"(B javac
$B$O0z?t$NL5$$%3%s%9%H%i%/%?$r$b$&:n$C$F$O$/$l$J$$$N$G!"<+J,$G
void
$B%-!<%o!<%I$r;}$?$J$$FC$B%G%U%)%k%H!&%3%s%9%H%i%/%?$N4+$a(B
class Dog {
private String name;
Dog() {
name = "Anonymonus";
}
Dog(String aName) {
name = aName;
}
public String getName() {
return name;
}
}
$B%3%s%9%H%i%/%?$N
TestConstructor.java
:
class Const {
//$B%a%s%PJQ?t(B
double x;
int y;
//$B%3%s%9%H%i%/%?(B
Const(double x, int y) {
this.x = x;
this.y = y;
}
//$B%3%s%9%H%i%/%?$N%*!<%P!<%m!<%I(B
Const(double x) {
this.x = x;
this.y = 15;
}
//$B%3%s%9%H%i%/%?$N%*!<%P!<%m!<%I(B
Const() {
this.x = 10;
this.y = 15;
}
//$B%a%=%C%I(B
double getMean() {
double z = this.x/this.y;
return z;
}
}
class TestConstructor {
public static void main(String args[]) {
double m1,m2;
//$B%$%s%9%?%s%9JQ?t@k8@(B
Const obj1;
Const obj2;
//$B%3%s%9%H%i%/%?8F$S=P$7!J%$%s%9%?%s%92=!K(B
obj1 = new Const(1059.0, 12);
obj2 = new Const(1298.0);
//$B%a%=%C%I8F$S=P$7(B
m1 = obj1.getMean();
m2 = obj2.getMean();
System.out.println("obj1: " + m1);
System.out.println("obj2: " + m2);
}
}
Const
$B%/%i%9$G$O%3%s%9%H%i%/%?$,Fs$DDj5A$5$l$F$$$^$9!#(Bmain()
$B$+$i!"$=$l$>$l$N%3%s%9%H%i%/%?$,8F$P$l$F$$$^$9$,!"0z?t$N8D?t$K1~$8$F!"BP1~$9$k%3%s%9%H%i%/%?$X@)8f$,0\$j$^$9!#$3$3$G$O!"0z?t$N%G!<%?7?$bH=Dj$5$l$^$9!#(Bobj1
$B$N:n@.$G$O!"0z?t$,Fs$D$"$k%3%s%9%H%i%/%?$,8F$P$l$F$$$^$9$+$i!"0l$DL\$N%3%s%9%H%i%/%?$K@)8f$,0\$j!"%a%s%PJQ?t(B x
$B$H(B y
$B$KCM$,BeF~$5$l$^$9!#$3$3$G!"(B this
$B%-!<%o!<%I(B$B$,IU$$$F$$$k$b$N$O!"$=$NJQ?t$,obj2
$B$N:n@.$G$O!"0z?t$,0l$D$@$1$N%3%s%9%H%i%/%?$,8F$P$l$F$$$^$9!#BP1~$9$k%3%s%9%H%i%/%?$OFs$DL\$K8+IU$+$j!"%G!<%?7?$bE,@Z$G$9!#$3$3$K@)8f$,0\$j!"%a%s%PJQ?t$,=i4|2=$5$l$^$9!#(B
C:\Java>javac TestConstructor.java
C:\Java>java TestConstructor
obj1: 88.25
obj2: 86.53333333333333
main()
$B%a%=%C%I$+$i;O$a$F!"@)8f$,$I$N$h$&$K0\$C$F$$$k$N$+(B$B%3%s%9%H%i%/%?$N%a%j%C%H(B
Copyright © 2001, 2003 SUGAI, Manabu. All Rights Reserved.
SEO
[PR] ?(IT(B ?(I((B?(I\(B?(IF(B?(I_(B???[?? Windows7 ???(I&(B?(I+(B?(IN(B??
?(I.(B?? ?f?(I&(B?(IB(B ?????^???T?[?o?[ ???C?u?`???b?g SEO