2010年8月24日
1..System.out.println (”TestB”); System.out.println("TestB");
有时候错误仅仅是因为标点的问题!
2.
class TestAA {
public void start() {
System.out.println("TestA");
}
}
class TestBB extends TestAA {
public void start() {
System.out.println("TestB");
}
}
((TestAA) new TestBB()).start();
new TestBB().start();
这两句话打印出来的都是TestB,为什么?
3.static final int a=10; 有没有这样子的用法。 Static和final放一起是啥意思。
4.Syntax error on token "age", VariableDeclaratorId expected after this token Cannot reduce the visibility of the inherited method from Info
接口中的常量必须初始化
我没有将其初始化,原代码如下:
public interface Info{
public String name;
void fun();
int age;
}
public class Test5 implements Info{
age=18;
void fun(){
System.out.println("Test5延用接口,年龄是"+age);
}
}
我还发现必须在void fun()函数加上public。我记得以前看过一句话,讲在继承的时候,子类方法的访问权限与父类访问权限的比较。下次记得再去看看。
2010年8月22日
1..float ff=3.1423254123f; System.out.println(ff);
这样子打印出来的ff结果是多少,关于小数点的截断,编译器是如何处理的?
2010年8月18日
1.一个对象只能有一种确切的数据类型
一个引用类型变量如果声明为父类的类型,但实际引用的是子类对象,那么该变量就不能再访问子类中添加的属性和方法。 ——我不是很清楚这句话的意思啊,为什么。
2.favor composition over inheritance什么意思
3.Constructor call must be the first statement in a constructor 这是什么意思
4.public class Test3 {
public Test3(String name){
System.out.println(name);
}
}
class Test32 extends Test3{
public void Tempfun(){
super("super的使用");
}
}
将public void Tempfun 改成Test32才对,为什么?
2010年8月5日
今天上午学习的内容有:StringBuffer类的一些方法;函数重载、函数重写、抽象类、抽象方法;static的使用
我思考的问题:
1.StringBuffer的产生,有什么优点呢?C里边有没有这样的东西。
2.函数重载和函数重写的概念还是不大清楚。今天的收获是以下一段代码:
public void receive(String s) {
System.out.println("Received a String");
System.out.println("s=" + s);
}
public int receive(int i,String s) {
System.out.println("Received a String and one int data");
return i;
}
然后像
public void receive(int i) {
System.out.println("Received one int data");
System.out.println("i=" + i);
}
public int receive(float i) {
return 1;
}
这样的代码同时出现,编译器是会报错的。
函数签名的概念我忘得差不多了,下次再回去看看。
3.
“而抽象类是可以有私有方法或私有变量的,实现抽象类可以有选择地重写需要用到的方法,但是必须实现里面所有的抽象方法。”
那为什么我写的代码没有去实现所有的抽象方法,可依然能行得通呢,编译不会报错啊。
abstract class Graphy{
abstract public double Calc();
abstract public void Test();
}
class Triangle extends Graphy{
public double Calc(double a,double b){
System.out.println("开始创建抽象方法");
return a*b/2;
}
}
main里边是
Triangle aTri=new Triangle();
System.out.println("面积是"+aTri.Calc(10, 10));
4.我觉得static这个东西真的很有意思。
2010年8月3日
1. t1.receive(3.14f);//收获,要加f
2010年8月2日
abstract class Graphy{
abstract public double Calc(){
System.out.println("开始创建抽象方法");
}
}
class Triangle extends Graphy{
public double Calc(double a,double b){
return a*b/2;
}
}
程序的执行结果是
面积是50.0
不会打印出 开始创建抽象方法
2010年7月28日
1.long now = System.currentTimeMillis(); 为什么会Duplicate local variable now
2010年7月27日
1. long now = System.currentTimeMillis();
System.out.println(now);
String s = String.format("%tR", now);
这段代码出错,这是为什么呢?
Exception in thread "main" java.lang.Error: Unresolved compilation problem:
The method format(String, Object[]) in the type String is not applicable for the arguments (String, long)
at com.fjnu.tulinying.Test.main(Test.java:39)
2.
The string "boo:and:foo", for example, yields the following results with these expressions:
Regex Result
: { "boo", "and", "foo" }
o { "b", "", ":and:f" }
执行String[] results = s.split("o");
为什么结果是 { "b", "", ":and:f" }
2010年7月24日
1. testStr="abc";
System.out.println(testStr);
System.out.println(testStr.hashCode());
String testStr2;
testStr2="abc";
System.out.println(testStr2.hashCode());
testStr与testStr2值相同的话,它们的hashCode也相同,hashCode是什么?
2.
String.charAt
If the char value specified by the index is a surrogate, the surrogate value is returned.
这句话什么意思
Returns the char value at the specified index. An index ranges from 0 to length() - 1. The first char value of the sequence is at index 0, the next at index 1, and so on, as for array indexing.
If the char value specified by the index is a surrogate, the surrogate value is returned.
Parameters:
index the index of the char value.
Returns:
the char value at the specified index of this string. The first char value is at index 0.
Throws:
IndexOutOfBoundsException - if the index argument is negative or not less than the length of this string.
3.
里边的argument是什么意思?
Concatenates the specified string to the end of this string.
If the length of the argument string is 0, then this String object is returned. Otherwise, a new String object is created, representing a character sequence that is the concatenation of the character sequence represented by this String object and the character sequence represented by the argument string.
Examples:
"cares".concat("s") returns "caress"
"to".concat("get").concat("her") returns "together"
Parameters:
str the String that is concatenated to the end of this String.
Returns:
a string that represents the concatenation of this object's characters followed by the string argument's characters.
4.
String testStr3="fda";
testStr3=testStr3.toUpperCase();//这里必须要testStr3=……不然没返回啊,那请问这种空的东西,一执行完该语句,编译器会自动给它清除掉么?
System.out.println(testStr3);
2010年7月20日
1.在子类型的非静态成员方法中访问其你类型的成员域,其格式为:super.父类型的成员域。啥叫“非静态成员方法”。
2010年7月18日
Person p=new Person();
Person p1=p;
p1和p的地址是一样的
今天对那个JAVA视频里说的什么堆啊栈啊的东西搞不太懂!
2010年7月17日
#include<stdio.h>
void fun(int i)
{
printf("调用fun函数,这下i=%d/n",i);
i++;
printf("调用fun函数,这下i=%d/n",i);
}
void main()
{
int i=1;
fun(i);
printf("返回到main函数,这下i=%d/n",i);
}
今天以前我一直以为 printf("返回到main函数,这下i=%d/n",i); 这样子打印出来的i是2
2010年7月15日
Integer x1=128;
Integer y1=128;
System.out.println(x1==y1);
答案是false,这个我还不理解,不知道Integer是什么,我一开始以为interger也行,原来不行。弄成int就肯定是true了 。
先收藏一下,以后碰到再说。
2010年7月11日
1.float f1=63.141512315464f;//收获:只能到63.141412
2.//方式1
System.out.println("age=" + age + " name=" + name + " other=" + other);
//方式2
System.out.println(String.format("age=%d name=%s other=%d",age,name,other))
3. char ch1='a';
ch1-=32;
System.out.println(ch1);
这样打印出来的是A
但是如果写成
char ch1='a';
System.out.println(ch1-32);
打印出来的是65
或者用System.out.println((char) (ch1-32));也能打印出A