class Default{
boolean t;
char c;
byte b;
short s;
int i;
long l;
float f;
double d;
public void show() {
System.out.println("基本类型 初始化值\n"+
"boolean<----->" + t +"\n" +
"char<----->" + c +"\n" +
"byte<----->" + b + "\n" +
"short<----->" + s + "\n" +
"int<----->" + i + "\n" +
"long<----->" + l + "\n" +
"float<----->" + f + "\n" +
"double<----->" + d + "\n"
);
}
}
public class InitValue {
public static void main(String[] args) {
Default d = new Default();
d.show();
}
}
class Person {
private String name;
// setter
}
class Default {
Person p;
public void show() {
System.out.println("Person<----->" + p);
}
}
public class InitValue {
public static void main(String[] args) {
Default d = new Default();
d.show();
}
}
class Default{
boolean t = true;
char c = 'A';
byte b = 47;
short s = 0xff;
int i = 24;
long l = 999;
float f = 1.2f;
double d = 1.732;
public void show() {
System.out.println(
"boolean<----->" + t +"\n" +
"char<----->" + c +"\n" +
"byte<----->" + b + "\n" +
"short<----->" + s + "\n" +
"int<----->" + i + "\n" +
"long<----->" + l + "\n" +
"float<----->" + f + "\n" +
"double<----->" + d + "\n"
);
}
}
public class InitValue {
public static void main(String[] args) {
Default d = new Default();
d.show();
}
}
class Person {
int i = set();
//...
}
class Person {
int i;
int j = set(i);
//...
}
class Person {
int age;
Person() {
age = 89;
}
}
class Pet {
Pet(int age) {
System.out.println("Pet(" + age + ")");
}
}
class Person {
Pet t1 = new Pet(1);
Person() {
System.out.println("---Person()---");
t3 = new Pet(33);
}
Pet t2 = new Pet(2);
void show() {
System.out.println("show----running");
}
Pet t3 = new Pet(3);
}
public class OrderOfInitialization {
public static void main(String[] args) {
Person p = new Person();
p.show();
}
}
class Bowl {
Bowl(int marker) {
System.out.println("Bowl(" + marker + ")");
}
void f(int marker) {
System.out.println("f(" + marker + ")");
}
}
class Table {
static Bowl b1 = new Bowl(1);
Table() {
System.out.println("Table()");
b2.f(1);
}
void f2(int marker) {
System.out.println("f2(" + marker + ")");
}
static Bowl b2 = new Bowl(2);
}
class Cupboard {
Bowl b3 = new Bowl(3);
static Bowl b4 = new Bowl(4);
Cupboard() {
System.out.println("Cupboard()");
b4.f(2);
}
void f3 (int marker) {
System.out.println("f3(" + marker + ")");
}
static Bowl b5 = new Bowl(5);
}
public class StaticInitialization {
public static void main(String[] args) {
System.out.println("Creating new Cupboard() in main");
new Cupboard();
System.out.println("Creating new Cupboard() in main");
new Cupboard();
t2.f2(1);
t3.f3(1);
}
static Table t2 = new Table();
static Cupboard t3 = new Cupboard();
}
class Person {
Person(int age) {
System.out.println("Person(" + age + ")");
}
void f(int age) {
System.out.println("f(" + age + ")");
}
}
class Persons {
static Person p1;
static Person p2;
static {
p1 = new Person(1);
p2 = new Person(2);
}
Persons() {
System.out.println("Persons()");
}
}
public class ExplicitStatic {
public static void main(String[] args) {
System.out.println("Inside main()");
Persons.p1.f(18);//1
}
static Persons x = new Persons();//2
static Persons y = new Persons();//2
}
class Person {
Person(int age) {
System.out.println("Person("+age+")");
}
}
class Persons {
static Person p = new Person(2); // 1
static {
p = new Person(3);
}
static Person p = new Person(2); // 2
}
public class CompStaticInit {
public static void main(String[] args) {
}
static Persons x = new Persons();
}
class Animal {
Animal(int age) {
System.out.println("Animal(" + age + ")");
}
void f(int age) {
System.out.println("f(" + age + ")");
}
}
public class NotStaticInit {
Animal a1;
Animal a2;
{
a1 = new Animal(1);
a2 = new Animal(2);
System.out.println("a1 & a2 initialized");
}
NotStaticInit() {
System.out.println("NotStaticInit");
}
public static void main(String[] args) {
System.out.println("Inside main()");
NotStaticInit x = new NotStaticInit();
}
}
class Insect {
int i = 1;
int j;
Insect() {
prt("i = " + i + ", j = " + j);
j = 2;
}
static int x1 = prt("static Insect.x1 initialized");
static int prt(String s) {
System.out.println(s);
return 3;
}
}
public class Beetle extends Insect {
int k = prt("Beeklt.k initialized");
Beetle() {
prt("k = " + k);
prt("j = " + j);
}
static int x2 = prt("static Bootle.x2 initialized");
static int prt(String s) {
System.out.println(s);
return 4;
}
public static void main(String[] args) {
prt("Beetle constructor");
Beetle b = new Beetle();
}
}
机械节能产品生产企业官网模板...
大气智能家居家具装修装饰类企业通用网站模板...
礼品公司网站模板
宽屏简约大气婚纱摄影影楼模板...
蓝白WAP手机综合医院类整站源码(独立后台)...苏ICP备2024110244号-2 苏公网安备32050702011978号 增值电信业务经营许可证编号:苏B2-20251499 | Copyright 2018 - 2026 源码网商城 (www.ymwmall.com) 版权所有