码迷,mamicode.com
首页 > 其他好文 > 详细

5.18下午

时间:2017-05-18 17:26:10      阅读:174      评论:0      收藏:0      [点我收藏+]

标签:tin   valueof   name   string   for   cond   action   xtend   call   

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下午

标签:tin   valueof   name   string   for   cond   action   xtend   call   

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

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!