◆ [转] JAVA interview trap second wave

xiaoxiao2021-03-06  56

1.

Abstract class name {

PRIVATE STRING NAME;

Public Abstract Boolean isstupidName (String Name) {}

}

What is wrong with the heroes?

Answer: wrong. Abstract Method must end with a semicolon and do not bring a curly bracket.

2.

Public class something {

Void dosomething () {

Private string s = "";

INT L = S.LENGTH ();

}

}

Is it wrong?

Answer: wrong. No access modifiers (private, public, and protected) before local variables

. Final can be used to modify partial variables

(Final like Abstract and Strictfp

It is non-access modifier, and stricTFP can only modify Class and ME.

THOD is not a variable).

3.

Abstract class something {

Private abstract string dosomething ();

}

It seems that there is nothing wrong?

Answer: wrong. Abstract Methods cannot be modified with private

. Abstract Methods is to make subclass item IMPLEMEN

T (implementation) specific details, how can I use Private Abstract?

CT

What is the Method blocking? (Similarly, Final can't add Final before Abstract Method).

4.

Public class something {

Public Int Addone (Final INT X) {

Return x;

}

}

This is more obvious.

Answer: wrong. INT X is modified to Final, meaning X cannot be modified in Addone Method.

5.