首页 > 其他 > 详细

5.18下午

时间:2017-05-18 17:21:35      阅读:354      评论:0      收藏:0      [点我收藏+]
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下午

原文:http://www.cnblogs.com/bgd140201228/p/6874424.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!