5.18下午

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了5.18下午相关的知识,希望对你有一定的参考价值。

Overview of the basic template of a Java class:

package declaration

import statements

access specifier class ClassName
{
}

access specifier is either "public", "private", "protected" or it can be unspecified.  If it is
unspecified then it has package visibility.

We extended the Fraction class to have a equals() method and a toString() method.
This was an example of method overriding.
We talked about how every class is a subclass of java.lang.Object.  We saw how
the subclass (which automatically extends Object) will ineritet the toString() and equals()
method from the parent class.  So we saw an example of inheritence, and also overloading
the inherited methods.

Implemented a main method in a TestFraction class, for testing the Fraction test using
assertions.  Throw Exception if assertion fails.  Since we throw new Exception() from
inside the main method, main must specifiy "throws Exception"

public static void main(String[] args) throws Exception 

{
   Fraction A = new Fraction(BigInteger.valueOf(1), BigInteger.valueOf(2);
   Fraction B = new Fraction(BigInteger.valueOf(1), BigInteger.valueOf(4);

   if (A.equals(B)) throw new Exception();  // assert false A.equals(B);
}

Also we discussed a few primitive types : int, long, float, double, boolean
and mentioned the auto-boxing and auto-unboxing between boolean and Boolean.  There are
corresponding boxed types for int (Integer), long (Long), float (Float), double (Double) also.

We covered 

3 types of loops:

for(;;){}   (very convenient syntax for conditional interation)
while(){}  (can be used to implement same logic as a for loop)
do{}while()   (body of loop is always executed the first time)

break (terminates the loop)
continue (skips to next iteration)

以上是关于5.18下午的主要内容,如果未能解决你的问题,请参考以下文章

练习5.18

5.18 Efficient Attention

5.18每日总结

5.18

5.18小结

5.18日学习总结对象和字符串