Wednesday, February 27, 2013

Java Certification



坑人的题目:
192;193;196;198;199;200;203;205; 224;228; 233;  244; 271, 275, 276, 284


1. invoke constructor: can only use this(); super(); or new // cannot use constructor name directly. 
2. Constructor call must be the first statement in a constructor
package test;

public class Hello {
String title;
int value;
public Hello(){
title += " World";
}

public Hello(int value){
this();//Constructor call must be the first statement in a constructor
this.value = value;
title = "Hello";
//Hello();  1. must call this()/2. 
}
}
3. ALL METHOD IMPLEMENTS FROM INTERFACE MUST BE DECLARED AS PUBLIC

4. Signature 一模一样 -> overriding
method name 一样,formal parameters 不一样 -> overloading

5. The final method can't be override in a subclass.
but, overloading a final method is perfectly legitimate.

6. File(File parent, String child)
          Creates a new File instance from a parent abstract pathname and a child pathname string.

7. Integer is primitive, even it is wrapped. int a = 400; int b = a; a, b share different memory space.

8.  DateFormat df = DateFormat.getDateInstance(DateFormat.LONG, Locale.ITALY)

9. string+int 直接转化为string

10. t.join()
The current thread invokes t.join() means that  the current thread  can only start
until t thread finish.

11. overriding: 父类没有throws Exception的情况下,子类不能throws Exception.

no Exception ------------------------------------ Exception

sub ---> super


子类不能抛出比父类大的Exception : RuntimeException例外


12.public variable in inner class can only be accessed from a class in the same package.

13. variables are shadowed while functions are override.

14. int [][] x   is   int []x[]

15. When an object is created, it's necessary to call the constructors of all super classes
to initialize their fields. Java does this automatically at the beginning if you don't. (by adding super();)

16. fields in interface are naturally public final static

17. & is bitwise 位运算符. && is logical.
& evaluates both sides of the operation.
&& evaluates the left side of the operation, if it's true, it continues and evaluates the right side.
18. Class Super{
 Super(int a){}

class Sub extends Super{
 //error, Sub(){super();} will be added automatically, but there is no Super(){} since Super(int a){} is already there and Super(){} will not be added in this case.
}


19. 
...catch(Exception e){...}
catch(NullPointerException npe){...}


Unreachable catch block for NullPointerException. 
It is already handled by the catch block for Exception

20. Initialization of int and Integer (member variables)
default: int -> 0 ;  Integer -> null

21. again, you don't have to catch RuntimeException

22. 
 static void yield() 
          Causes the currently executing thread object to temporarily pause and allow other threads to execute.

ex:
{...
yield();
...}

23. Type Casting Q147

1.compiler will check that there objects are in inheritance tree or not . If they are in tree then it will compile. Otherwise -> compile error.

2.At runtime,actual object will be checked before casting. Here x is not object of Delta so it will fail at runtime.

24.   
  String s = "hello 12 3 wo 2";
  Scanner sc = new Scanner(s);
  System.out.print(sc.nextInt());//java.util.InputMismatchException
if
  String s = "   12 3 2"; //  output: 12
if
  String s = ", 12 3 2";//java.util.InputMismatchException

25. 
没有指定generic type  -> check the Data structure type only. 

26. label must be placed right before the loop Q179

27. A method with the same signature as a private final method in class X can be implemented in a subclass of X. 


class A{ private final void go(){}}
class B extends A{ void go(){}}  // even sharing the same signature, those go() methods have no business with each other.

28 . overriding: return type 是同一个Inheritance Tree 就可以了

29. Overloading depends on just signature not return type.

30. super.method1(); is illegal if method1 is static in super class

1. static methods can’t override.
2. super method use in case of override

31. for loop doesn't expect a iterator object: it expects a collection

32.  subclass 不继承 superclass的 private variables & private method.
但是public, default, protected的variables可以直接在subclass里面直接使用也可以在variable前面加'this.'


33. 在一个class中看到implement来自interface的method,一定要确认它是public method.

34. 看到super class的constructor有formal parameter,确认一下其有没有加上无参constructor. 因为在这种情况下JVM不会自动加。


No comments:

Post a Comment