马上注册,结交更多好友,享用更多功能^_^
您需要 登录 才可以下载或查看,没有账号?立即注册
x
本帖最后由 回忆一遥远 于 2017-8-16 07:37 编辑
练习一
练习class T{
int a;
char b;
}
public class IniClas {
public static void main(String[] args){
T c = new T();
System.out.println("a = " + c.a);
System.out.println("b = " + c.b);
}
}
输出答
Java 类中的元素会执行默认初始化过程
练习二
练习+结果
练习三
练习 无结果class ATypeName{
int a;
}
public class Test13 {
public static void main(String[] args){
ATypeName a = new ATypeName();
a.a = 10;
}
}
练习四class DataOnly{
int i;
double d;
boolean b;
}
public class Test14 {
public static void main(String[] args){
DataOnly data = new DataOnly();
data.i = 23;
data.d = 2.4;
data.b = false;
}
}
练习五
练习class DataOnly{
int i;
double d;
boolean b;
}
public class Test14 {
public static void main(String[] args){
DataOnly data = new DataOnly();
data.i = 23;
data.d = 2.4;
data.b = false;
System.out.println("i = " + data.i);
System.out.println("d = " + data.d);
System.out.println("b = " + data.b);
}
}
结果
练习六
练习public class Test {
static int storage(String s){
return s.length() * 2;
}
public static void main(String[] args){
System.out.println(storage("Hello"));
}
}
结果
练习七
练习class StaticTest{
static int i = 24;
}
class Incrementable{
static void increment(){
StaticTest.i++;
}
}
public class Test {
public static void main(String[] args){
StaticTest st1 = new StaticTest();
StaticTest st2 = new StaticTest();
System.out.println("st1 = " + st1.i);
System.out.println("str2 = " + st2.i);
Incrementable sf = new Incrementable();
sf.increment();
System.out.println("st1 = " + st1.i);
System.out.println("str2 = " + st2.i);
}
}
结果st1 = 24
str2 = 24
st1 = 25
str2 = 25
|