System.out.format("Pi is approximately %d.", Math.PI);
请问执行的结果是什么?
public class Certkiller3 implements Runnable {
public void run() {
System.out.print("running");
}
public static void main(String[] args) {
Thread t = new Thread(new Certkiller3());
t.run();
t.run();
t.start();
}
}
执行的结果是?
public class ComplexCalc {
public int value;
public void calc() {value += 5;}
}
代码片段2: public class MoreComplexCalc extends ComplexCalc {
public void calc() {value -= 2;}
public void calc(int multi) {
calc();
super.calc();
value *= multi;
}
public static void main(String[] args) {
MoreComplexCalc calc = new MoreComplexCalc();
calc.calc(3);
System.out.println("Oh it is:" + calc.value);
}
}
请问编译运行的结果是什么? 1. public class Person {
2. private String name;
3. public Person(String name) {this.name = name;}
4. public boolean equals(Person p) {
5. return p.name.equals(this.name);
6. }
7. }
那个选项的描述是正确的? public class JavaContest {
public static void main(String[] args) throws Exception {
Thread.sleep(3000);
System.out.println("alive");
}
}
请问编译运行的结果是什么?
public void aSafeMethod(Object value) {
//在这里检查方法的参数
//这里省略其他代码
System.out.println(value.toString());
}
代码中的方法要求传入的参数是非空的,请问有什么比较好的方法去处理一个空值?
public static void main(String[] args) {
method1(1,2);
System.out.print(" java");
}
public static void method1(int x1, int x2) {
System.out.print("hello");
}
public static void method1(int x1, int x2, int x3) {
System.out.print("hi");
}
请问编译运行的结果是什么? void waitForSignal() {
Object obj = new Object();
synchronized (Thread.currentThread()) {
obj.wait();
obj.notify();
}
}
以下哪一个描述是正确的?
package certkiller;
class Target {
public String name = "hello";
}
哪些类能够直接访问并且改变name这个变量的值。
int i = 1;
while(i != 5) {
switch(i++%3) {
case 0:
System.out.print("A");
break;
case 1:
System.out.print("B");
break;
case 2:
System.out.print("C");
break;
}
}
请问编译运行的结果是什么?
public class Test {
public Test() {
System.out.print("test ");
}
public Test(String val) {
this();
System.out.print("test with " + val);
}
public static void main(String[] args) {
Test test = new Test("wow");
}
}
请问编译运行的结果是什么? String text = "Welcome to Java contest";
String[] words = text.split("\s");
System.out.println(words.length);
请问编译运行的结果是什么?
public class Test {
private int a;
public int b;
protected int c;
int d;
public static void main(String[] args) {
Test test = new Test();
int a = test.a++;
int b = test.b--;
int c = test.c++;
int d = test.d--;
System.out.println(a + " - " + b + " - " + c + " - " + d);
}
}
请问那个说法是正确的?有如下变量声明:
Map<String, ? extends Collection<Integer>> map;请问以下那个赋值语句会出错?
contestKiller = new ReallyBigObject();
//这里省略部分代码
contestKiller = null;
/*在这里补充代码*/
下列哪一选项的代码是告诉虚拟机尽最大的能力去回收
contestKiller
这个对象所占用的内存。
11. public static int getSum(List list) {
12. int sum = 0;
13. for(Iterator iter = list.iterator(); iter.hashNext();) {
14. int i = ((Integer) iter.next()).intValue();
15. sun += i;
16. }
17. return sum;
18. }
为了适应泛型,需要对代码做以下那三项改动?
public abstract interface Sudo {
public void crazy(String s);
}
请问以下哪些选项中的类定义是正确的?
public abstract class MySudo implements Sudo {
public abstract void crazy(String s) {}
}
public class Test {
public static void main(String[] args) {
int i = 3, j;
outer:while(i > 0) {
j = 3;
inner:while(j > 0) {
if(j < 2) break outer;
System.out.println(j + " and " + i);
j--;
}
i--;
}
}
}
请问以下哪些选项的内容会出现在输出中?
import java.io.*;
class Directories {
static String[] films = {"sora", "shu"};
public static void main(String[] args) {
for(String fp ; films) {
//在这里插入第一句代码
File file = new File(path, args[0]);
//在这里插入第二句代码
}
}
}
有一个文件夹,它有2个子文件夹,分别是“
sora
”和“
shu
”, "
sora”
里面只有名为“
aoi.txt
”的文件,“
shu
”里面只有名 为“
qi.txt
”的文件。
public class Square {
public static long square(long v) {
return v * v;
}
public static double square(double d) {
return d * d;
}
}
你可以直接将上面代码输入答案框提交。
public class Square {
public static long square(long v) {
return v * v;
}
public static double square(double d) {
return d * d;
}
}
[保存]
public class MyHelloWorld implements HelloWorld {
public String sayHelloWorld(String name) {
return name + " say: hello world!";
}
}
你可以直接将上面代码输入答案框提交。
1 public interface HelloWorld {
2 /**
3 *返回name + " say: hello world!".
4 */
5 String sayHelloWorld(String name);
6 }
请您写出一个类名为MyHelloWorld的类,要求能满足题意。[代码编辑区]
public class MyHelloWorld implements HelloWorld {
public String sayHelloWorld (String name) {
return name + " say: hello world!";
}
}
[保存]
1 public abstract class Shape {
2 /**
3 *计算形状的面积
4 */
5 abstract public int getArea();
6 }
请您写出一个类名为Rectangle的类,要求能满足题意。[代码编辑区]
public class Rectangle extends Shape {
int width,height;
public Rectangle(int i, int j) {
this.width = i;
this.height = j;
}
public void setWidth(int i) {
this.width = i;
}
public void setHeight (int i) {
this.height = i;
}
public int getWidth() {
return width;
}
public int getHeight() {
return height;
}
public int getArea() {
// TODO Auto-generated method stub
return width * height;
}
}
[保存]
/**
*精简的列表(List),用于储存一系列的元素(对象)。
*IList里面储存的元素会按插入的顺序排放,也能根据下标获取这些元素。下标从0开始。
*/
public interface IList {
/**
*往列表的尾部增加一个元素
*/
void add(Object o);
/**
*获取下标所指定的元素。当下标越界时抛出异常java.lang.IndexOutBoundsException
*/
Object get(int i);
/**
*获取列表里当前元素的个数
*/
int size();
/**
*清空列表,移除列表里所有的元素
*/
void clear();
}
请您写出一个类名为MyList的类,要求能满足题意。[代码编辑区]
import java.util.ArrayList;
import java.util.List;
public class MyList implements IList {
List list = null;
public MyList() {
list = new ArrayList();
}
public void add(Object o) {
// TODO Auto-generated method stub
list.add(o);
}
public Object get(int i) {
// TODO Auto-generated method stub
if (i > list.size()) {
throw new IndexOutOfBoundsException("大小不对");
}
return list.get(i);
}
public int size() {
// TODO Auto-generated method stub
return list.size();
}
public void clear() {
// TODO Auto-generated method stub
list.clear();
}
}
[保存]
以上就是模拟测试题了,答案通过测试。
希望对你有所帮助!!!