问题1:书上说:“常将一个类保存为一个文件”。当时的疑问是:那么运行程序的时候是要把所在的文件夹都搜一遍的吗?java
问题2解决方案:形参是仅当方法调用时才会存在的,在方法调用结束时消亡。git
问题3解决方案:
如图:当改变hyt时,gk的值也会跟着改变。编程
问题4解决方案:百度:没法保证一个接口就一个类去实现,多个类去实现同一个接口,程序怎么知道他们是有关联的?(多重继承是被禁止的)安全
问题1:写了一段代码,编译的时候出现了如图错误:
app
问题1解决方案:通过一番尝试和对书上例题的参考,发现了错误所在:在编写类的时候,构造方法中的参数(形参),写了好几个(当时还不知道括号里写这个是干吗用的),而在写驱动类的程序中实例化的时候没有按照格式写好参数致使的错误,改正后的代码如图:
less
问题2:在写一个修改器方法的时候,我像书上同样设置成了不返回值型void,而我后来写的驱动类程序的时候,须要把设置的数值用来计算,结果是这样:
dom
问题2解决方案:找不到符号,屡次尝试以后,将void去掉了,设置了返回类型,结果成功编译。可是输出的结果并非预期结果,如图:
当前直径是用修改器方法设置好的,也返回出来了,表面积也是计算出来了,只有体积算不出来。想了一下,把程序中要除以的6改为了6.0,成功运行了。
(记录一下这个小失误)iphone
问题3:跟上面的出现了类似的状况,找不到符号,如图:
tcp
问题3解决方法:跟上面的状况不一样,此次是在写实际参数的时候,字符串没加引号。ide
问题4解决方法:后来试了一下修改方法,是能够的。驱动程序没问题,那就是类有问题了,代码如图:
上课的时候恍惚间听见老师说能够将形参的名字写成变量的名字同样,并且不会报错,因此一开始我就这样作了,就出现了上述状况。后来改为了如上图所示,在驱动类的实参写的字符串就能正常getX到了。
这里还要记录一下,在用布尔值表示这辆车是否为古董车的时候,我用了startsWith方法。判断它的出厂年份减去四十五以后,是正值仍是负值,即判断有没有负号。可是有一个问题就是,要想进行减法运算,得把年份设成数值型,只有将减过以后的结果变成字符串才能用那个方法判断结果有没有“-”。代码如图:
错题1: If two variables contain aliases of the same object then
A .the object may be modified using either alias
B .the object cannot be modified unless there's but a single reference to it
C .a third alias is created if/when the object is modified
D .the object will become an "orphan" if both variables are set to null
E .answers A and D are correct
缘由:根据定义,别名提供了能够修改对象的方法(别名就像指针)。根据定义,别名提供了能够修改对象的方法(别名就像指针)。若是两个变量都被设置为null,那么这个对象就不会被任何变量引用(经过任何别名),并且它确实会变成一个“孤儿”,而且在未来某个时候会被垃圾收集。
错题2 Which properties are true of String objects?
A .Their lengths never change
B .The shortest string has zero length
C .Individual characters within a String may be changed using the replace method
D .The index of the first character in a string is one
E .Only A and B are true
缘由:字符串是不可变的。这意味着一旦建立了字符串对象,就不能更改它。所以,字符串的长度在建立后不会改变。最短长度的字符串是“”,引号之间没有字符,因此长度为零。replace方法容许您从原始的字符串中建立一个新的字符串,替换一些字符。字符串中第一个位置的索引是0,而不是1。另外,每一个字符串的最后一个字节包含了字符串的末尾字符,它是一个低值或二进制零的字节。
错题3: What is output with the statement System.out.println(x+y); if x and y are int values where x=10 and y=5? (若是x和y是int类型的数值,x=10,y=5,那么语句System.out.println(x+y);的输出是什么?)
A .15
B .105
C .10 5
D .x+y
E .An error since neither x nor y is a String (因x和y都不是字符串而引发的一个错误)
缘由:这里的x和y是变量,存储着数值,“+”起的是加号的做用,不是链接符。
错题4: What happens if you attempt to use a variable before it has been initialized?
A .A syntax error may be generated by the compiler
B .A runtime error may occur during execution
C .A "garbage" or "uninitialized" value will be used in the computation
D .A value of zero is used if a variable has not been initialized
E .Answers A and B are correct
缘由:不少时候,编译器可以检测到未初始化变量的尝试使用,在这种状况下会产生语法错误。若是在编译器中使用脱逃检测,那么在使用时就会出现运行时错误。Java是一种很是“安全”的语言,所以若是在计算中使用未初始化的变量,它不容许使用“垃圾”或“0”。
错题5: What is the function of the dot operator?
A . It serves to separate the integer portion from the fractional portion of a floating point number
B . It allows one to access the data within an object when given a reference to the object
C . It allows one to invoke a method within an object when given a reference to the object
D . It is used to terminate commands (much as a period terminates a sentence in English)
E . Both B and C are correct
缘由:没有任何机制能够,但有方法能够执行相似的操做,并返回一个字符在一个给定的位置(charAt)或返回int。
错题6:
In the StringMutation program shown in Listing 3.1, if phrase is initialized to "Einstein" what will Mutation #3 yield if Mutation #1: mutation1 = phrase.concat(".")?
A .Einstein.
B .EINSTEIN.
C .XINSTXIN.
D .einstein.
E .xinstxin.
缘由:突变#2将每一个字母更改成大写。而后突变#3用Xs替换了Es。
错题7:
Say you write a program that makes use of the Random class, but you fail to include an import statement for java.util.Random (or java.util.*). What will happen when you attempt to compile and run your program.
A .The program won't run, but it will compile with a warning about the missing class.
B .The program won't compile-you'll receive a syntax error about the missing class.
C .The program will compile, but you'll receive a warning about the missing class.
D .The program will encounter a runtime error when it attempts to access any member of the Random class
E .none of the above
缘由:缺乏的类意味着将有未定义的变量和/或方法。编译器将检测这些并将发出错误消息。你的程序没法执行。
错题8:
The String class' compareTo method
A .compares two string in a case-independent manner
B .yields true or false
C .yields 0 if the two strings are identical
D .returns 1 if the first string comes lexically before the second string
E .none of the above
缘由:若是两个字符串是相同的,那么就会获得0。若是第一个字符串在第二个字符串以前出现,那么-1若是第一个字符串在第二个字符串后面出现,则为+1。
错题9:
The advantage(s) of the Random class' pseudo-random number generators, compared to the Math.random method, is that
A .you may create several random number generators
B .the generators in Random are more efficient than the one in Math.random
C .you can generate random ints, floats, and ints within a range
D .you can initialize and reinitialize Random generators
E .all but answer B
缘由:全部随机数生成器的效率是相同的。随机生成器优于数学的优势。随机包含全部其余属性。
代码行数(新增/累积) | 博客量(新增/累积) | 学习时间(新增/累积) | 重要成长 | |
---|---|---|---|---|
目标 | 5000行 | 30篇 | 400小时 | |
第一周 | 309/309 | 1/1 | 20/20 | |
第二周 | 269/578 | 1/2 | 18/38 | |
第三周 | 236/776 | 1/3 | 22/60 | |
第四周 | 507/1283 | 2/5 |