Java Reference
In-Depth Information
publicSeries(inta,intd,intn){
this.a=a;
this.d=d;
this.n=n;
}
publicintcomputeSum(intkind){
intsum=a,t=a,i=n;
while(i-->1){
if(kind==ARITHMETIC){
t+=d;
}elseif(kind==GEOMETRIC){
t=t*d;
}
sum+=t;
}
returnsum;
}
publicstaticvoidmain(String[]args){
inta=Integer.parseInt(args[0]);
intd=Integer.parseInt(args[1]);
intn=Integer.parseInt(args[2]);
Seriess=newSeries(a,d,n);
System.out.println("Arithmeticsum="
+s.computeSum(Series.ARITHMETIC));
System.out.println("Geometricsum="
+s.computeSum(Series.GEOMETRIC));
}
}
j-- is quite rich. Although j-- is a subset of Java, it can interact with the Java API. Of
course, it can only interact to the extent that it has language for talking about things in
the Java API. For example, it can send messages to Java objects that take int , boolean ,
or char arguments, and which return int , boolean , and char values, but it cannot deal
with float s, double s, or even long s.
As for Java, only one of the type declarations in the compilation unit (the file containing
the program) can be public , and that class's main() method is the program's entry point 1 .
Although j-- does not support interface classes, it does support abstract classes. For
example,
packagepass;
importjava.lang.System;
abstractclassAnimal{
protectedStringscientificName;
protectedAnimal(StringscientificName){
this.scientificName=scientificName;
}
publicStringscientificName(){
returnscientificName;
}
}
classFruitFly
1 A program's entry point is where the program's execution commences.
 
Search WWH ::




Custom Search