NO.1: Generics(泛型)
package cn.com.hrbust.Test;
public class Generics {
public static void main(String[]args) {
Chorus<Singer, Instrument>model = new Chorus<Singer,Instrument>();
Singer JJ = new Singer();
Instrument piano = new Instrument();
model.makeChorus(JJ, piano);
}
}
class Chorus<E,F> {
void makeChorus(E person,F instrument) {
person.toString();
instrument.toString();
}
}
class Singer {
public String toString() {
System.out.println("lalallala");
return "";
}
}
class Instrument {
public String toString() {
System.out.println("|455|8784|");
return "";
}
}
No.2:Exception(异常)
package cn.com.hrbust.Test;
public class Exception {
public static void main(String[]args) {
B b = new B();
try {
b.f(100);
b.f(-9);
} catch (MyException e) {
System.out.println(e.getMessage());
}
}
}
class MyException extends Throwable {
String message;
MyException(int n) {
message = n+"不是正数";
}
public String getMessage() {
return message;
}
}
class B{
public void f(int n) throws MyException {
if(n<0) {
MyException e = new MyException(n);
throw(e);
}
double number = Math.sqrt(n);
System.out.println(n+"的平方根:"+number);
}
}
No.3:内部类VS外部类
package nice;
public class InnerClassDemo {
public static void main(String[]args) {
// Outer o = new Outer();
// Outer.Inner inner = o.new Inner();
// inner.display();
Outer outer = new Outer();
outer.inst();
}
}
class Outer {
int score = 100;
void inst() {
class Inner {
void display() {
System.out.println("score is "+score);
}
}
Inner inner = new Inner();
inner.display();
}
// class Inner {
// String name = "zhangsan";
// void display() {
// System.out.println("score is "+score);
// }
}
// public void print() {
// Inner inner = new Inner();
// System.out.println(inner.name);
// }
NO.4:与接口有关的内部类
package cn.com.hrbust.Test;
interface Show {
public void show();
}
class A {
void f(Show s) {
s.show();
}
}
public class Interface {
public static void main(String[]args) {
A a = new A();
a.f(new Show() {
public void show() {
System.out.println("Hello");
}
});
}
}
NO.5:Integer。parseInt and Integer.toString
package cn.com.hrbust.Test;
public class Test {
public static void main(String[]args)throws NumberFormatException
{
System.out.println(Integer.parseInt("285527")+1);
System.out.println(Integer.toString(123)+1);
}
}