1 / 32
文档名称:

JAVA总结.doc

格式:doc   大小:119KB   页数:32页
下载后只包含 1 个 DOC 格式的文档,没有任何的图纸或源代码,查看文件列表

如果您已付费下载过本站文档,您可以点这里二次下载

分享

预览

JAVA总结.doc

上传人:sunny 2021/9/17 文件大小:119 KB

下载得到文件列表

JAVA总结.doc

相关文档

文档介绍

文档介绍:JAVA总结
2
JAVA
1、public class FuncMain{ //
/*public static void main(string[] args) { //--(1)--
("Hello main() method");
}*/
运行:找不到符号
/*public void static main(String[] args) { //--(2)--
("Hello main() method");
}*/
运行:方法声明无效,需要返回类型
/*public static void main(String[] args) { //--(3)--
("Hello main() method");
}*/
运行结果:Hello main() method
/*public static int main(String[] args) { // --(4)--
("Hello main() method");
}*/
运行:缺少返回语句
}
2、public class Foo{
public static void main(String args[]){
String s=null;
("s="+s);
}
}
改前:可能尚未初始化变量 s
s =null
3、public class Test {
static int s;
public static void main(String[] args) {
3
Test t = new Test();
();
(s);
}
void start() {
int x = 7;
twice(x);
(x + " ");
}
void twice(int x){
x = x*2;
s = x;
}
}
运行结果:7 14
4、public class Foo{
public static void main(String[] args){
StringBuffer a = new StringBuffer("A");
StringBuffer b = new StringBuffer("B");
operate(a,b);
(a+","+b);
}
static void operate(StringBuffer x, StringBuffer y){
(x);
y=x;
}
}
运行结果:A,BA
4
5、package xcom;
public class Useful {
int increment(int x) { return ++x; }
}
import xcom.*; //Needy3与Useful 不在同一个包 // line 1
public class Needy3 {
public static void main(String[] args) {
u = new (); // line 2
((5));
}
}
运行结果:6
6、(数组越界)class Fork {
public static void main(String[] args) {
if( == 1 || args[1].equals("test")) {//改为 if( == 0
("test case");
} else {
("production " + args[0]);