
java基础
文章平均质量分 80
lili6755
Iam Lili.
展开
-
静态工厂方法构造对象优缺点
对于一个类,要获取它的一个实例,通常的做法是提供一个公用的构造函数,然而还有另一种方法,我们称之为静态工厂方法,实质上也就是一个简单的静态方法,它返回一个类的实例。其实,静态工厂方法获取对象实例,我们并不陌生,我们来看看API中的一个实例:java.lang.Boolean类:public static Boolean valueOf(boolean b){ return原创 2009-12-03 12:40:00 · 1531 阅读 · 1 评论 -
SCJP试题七
685. For an object to be a target for a Thread, that object must be of type:Fill in the blank.正确答案: Runnable 686. If you supply a target object when you create a new Thread, as in:Thread t=n转载 2009-12-23 23:48:00 · 1109 阅读 · 0 评论 -
SCJP试题五
600. Your chief Software designer has shown you a sketch of the new Computer parts system she is about to create. At the top of the hierarchy is a Class called Computer and under this are two child cl转载 2009-12-23 15:40:00 · 1153 阅读 · 0 评论 -
SCJP试题四
void test(){if (!Test.this.flag);{sample();}}private boolean flag = false;}publi void sample(){System.out.println("Sample");}public Test(){(new Inner()).test();}public sta转载 2009-12-23 15:38:00 · 909 阅读 · 0 评论 -
SCJP考题十
10.What output is produced by the following program?class Test{public static void main(String args[]){long size=10;int[] array=new int[size];size=20;System.out.println(array.length);}}转载 2009-12-23 14:59:00 · 858 阅读 · 0 评论 -
SCJP试题十四
615. Given the following class definition:public class Droitwich{class one {private class two{public void main(){System.out.println("two");}}}}Which of the following statements are转载 2009-12-23 23:55:00 · 750 阅读 · 0 评论 -
SCJP试题六
930. What String instance method would return true when invoked like this?a.method(b);Where a="GROUNDhog" and b="groundHOG"?Select the one right answer.A. equals()B. toLowerCase()C. toUppe转载 2009-12-23 23:45:00 · 2033 阅读 · 0 评论 -
SCJP试题三
B. float f=-412;C. int other=(int)true;D. double d=0x12345678;E. short s=10;正确答案: A、B、D、E 444. What is the result of executing the following code:class Test{public static void main(转载 2009-12-23 15:36:00 · 1027 阅读 · 0 评论 -
SCJP试题二
int index;Test(int mpg){milesperGallon=mpg;index=0;}Test(){}public static void main(String[] args){int index;Test c=new Test(25);if(args.length>0)if(args[index].equals("Hiway"))转载 2009-12-23 15:33:00 · 770 阅读 · 0 评论 -
SCJP十二
1. What will happen when you compile and run this program: class Test{pubilc static void main(String[]args){int length=100;int[] d=new int[length];for(int index=0;indexSystem.out.println(d[index]);}}S转载 2009-12-23 15:22:00 · 592 阅读 · 0 评论 -
SCJP试题十一
564. What will appear in the standard output when you run the Tester class?class Tester{int var;Tester(int var){this ("hello");}Tester(String s){this();System.out.println(s);}Teste转载 2009-12-23 15:19:00 · 1301 阅读 · 0 评论 -
SCJP试题十六
1. Wich three are valid declarations of a char?(choose three)A char c1=064770;B char c2=’face’;C char c3=0Xbeef;D char c4=/u0022;E char c5=’/iface’;F char c6=’/ufac转载 2009-12-23 23:57:00 · 1094 阅读 · 0 评论 -
SCJP试题十五
22. A Java array is an ordered collection of three kinds of things. What are they?Fill in the blank.正确答案:primitives. object references, references to other arrays. 20. There are seven chara转载 2009-12-23 23:56:00 · 692 阅读 · 0 评论 -
SCJP试题八
880. If you run the following code on a on a PC from line directory c:/ source:import java.io.*;class Test {public static void main(String[] args) throws Exception{File file = new File("Ran.te转载 2009-12-23 23:49:00 · 900 阅读 · 0 评论 -
SCJP试题一
Section(部分,节):Language Fundamentals(基本原则)Problem[1]A method is ...[Select One][1]an implementation of an abstraction.[2]an attribute defining the property ofa particular abstraction[3]a转载 2009-12-23 15:29:00 · 998 阅读 · 0 评论 -
SCJP十三
子类的构造函数会自动调用父类无参数的构造函数 在重写中,所谓子类中方法的访问控制不能比父类中方法的访问控制范围窄是指:Ø 一个package方法可以被重写为package、protected和public的Ø 一个protected方法可以被重写为protected和public的Ø 一个public方法只可以被重写为public的局部变转载 2009-12-23 15:23:00 · 618 阅读 · 0 评论 -
hashcode解析
hashcode是个啥?它与equals的关系? 1.hashcode 拆开看hash可以理解为一种hash算法,经过算法后会得出一个值就叫code,于是得到了我们的hashcode.但是经过计算得到的hashcode不一定是唯一的,比如8/3,7/3结果都是2,这时候我们的对象拥有了相同的hashcode,可以理解为他们被放进了"2" 这个箩里面 2.equals equals是进一步对对象的比转载 2009-12-23 10:35:00 · 657 阅读 · 0 评论 -
java中equals和==的区别
值类型是存储在内存中的堆栈(以后简称栈),而引用类型的变量在栈中仅仅是存储引用类型变量的地址,而其本身则存储在堆中。==操作比较的是两个变量的值是否相等,对于引用型变量表示的是两个变量在堆中存储的地址是否相同,即栈中的内容是否相同。equals操作表示的两个变量是否是对同一个对象的引用,即堆中的内容是否相同。==比较的是2个对象的地址,而equals比较的是2个对象的内容。显然,当equals为t转载 2009-12-23 10:05:00 · 664 阅读 · 0 评论 -
SCJP试题九
564. What will appear in the standard output when you run the Tester class?class Tester{int var;Tester(double var){This.var=(int)var;}Tester(int var){this ("hello");}Tester(String s)转载 2009-12-23 23:51:00 · 1485 阅读 · 1 评论