提交 ce03f5cd 编写于 作者: 武汉红喜's avatar 武汉红喜

lang

上级 ba494978
package org.hongxi.java.util.lang;
/**
* @author shenhongxi 2019/8/11
*/
public abstract class Animal {
private int type;
Animal() {
System.out.println("Animal()");
}
Animal(int type) {
this.type = type;
}
abstract void run();
}
package org.hongxi.java.util.lang;
/**
* @author shenhongxi 2019/8/11
*/
public class Cat extends Animal {
private int color;
Cat() {
System.out.println("Cat()");
}
Cat(int type, int color) {
super(type);
this.color = color;
}
@Override
void run() {
System.out.println("Cat#run()");
}
}
package org.hongxi.java.util.lang;
/**
* @author shenhongxi 2019/8/11
*/
public class ChinaCat extends Cat {
private int province;
ChinaCat() {
System.out.println("ChinaCat()");
}
@Override
void run() {
System.out.println("ChinaCat#run()");
}
public static void main(String[] args) {
Animal animal = new ChinaCat();
animal.run();
}
}
package org.hongxi.java.util.lang;
/**
* Created by shenhongxi on 2017/11/17.
*/
public class CodeBlockTest {
int a = 110;
static int b = 112;
// static CodeBlockTest instance = new CodeBlockTest(); // 这种情况输出的是2 3 1 4
static {
System.out.println("1 b=" + b); // b=112
}
{
System.out.println("2 a=" + a + " b=" + b); // a=110 b=112
}
CodeBlockTest() {
System.out.println("3 a=" + a + " b=" + b); // a=110 b=112
}
public static void main(String[] args) { // 1 2 3 2 3 4
new CodeBlockTest();
new CodeBlockTest();
System.out.println("4");
}
}
package org.hongxi.java.util.lang;
/**
* Created by shenhongxi on 2018/6/1.
*/
public class ExTest {
public static void main(String[] args) {
System.out.println(t(-10));
}
private static int t(int i) {
try {
System.out.println("try lock");
try {
if (i < 0) {
throw new RuntimeException("i<0");
}
if (i > 100) {
return -2;
}
i++;
} finally {
System.out.println("release lock");
}
return i;
} catch (Exception e) {
return -1;
}
}
}
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册