1)
Class Valhold {
Public INT i = 10;
}
Public class obparm {
Public void amethod () {
Valhold v = new Valhold ();
Another (V);
System.out.println (V.I);
}
Public void another (Valhold V) {
v.i = 20;
Valhold vh = new valhold ();
v = VH;
System.out.println (V.I);
}
Public static void main (string [] argv) {
Obparm o = new obparm ();
O. AMETHOD ();
}
}
Why is the program operation result, if the compilation error indicates the cause of the error
answer:
10
20.
2)
Class a {
Public static void a () {
System.out.println ("super!");
}
Public string toString () {
Return "a!";
}
}
Class testStatic extends a {
Public static void a () {
System.out.println ("Child!");
}
Public static void main (String [] args) {
A obj = new testStatic ();
System.out.println (OBJ);
Obj.a ();
}
}
Output results, if compiling errors indicate the cause of the error.
answer:
STATIC, output
A!
Super!
3)
Public class inc
Public static void main (String Argv []) {
INC = New INC ();
INT i = 0;
Inc.fermin (i);
i = i ;
System.out.println (i);
}
Void Fermin (INT i) {
i ;
}
}
Output result, if compiling errors indicate the cause of the error
answer:
0;
4)
PUBLIC Class Agg {
Static public int i = 10;
Public static void main (String Argv []) {
Switch (i) {
Case 1:
System.out.println ("One");
DEFAULT:
System.out.println ("Default");
Case 10:
System.out.println ("Ten");
}
}
}
Output results:
answer:
DEFAULT, TEN.
5)
Boolean flag = false;
IF (Flag = true) {
System.out.println ("True");
} else {
System.out.println ("False");
}
Output result, if the compilation error, pointing out the error ..
answer:
True
6)
Public class test {
Public static void test () {
this.print ();
}
Public static void print () {
System.out.println ("Test");
}
Public static void main (string args []) {
Test ();
}
}
Output results, if compiled errors, pointed out the error.
answer
Compilation error, static method can not use this7)
StringBuffer SB = New StringBuffer ("abc");
2.String s = new string ("abc");
3.SB.Append ("def");
4.S.Append ("DEF");
5.sb.insert (1, "zzz");
6.s.concat (sb);
7.s.trim ();
Point out which illegal, explanation
answer
4 and 6 illegal
Reason: String belongs to the wrapping class, also known as unable class
8) What is wrong with the initialization of an array?
1 int A [] = {1, 2, 3};
2 int [] b [] = {{1, 2, 3}, {1, 2, 3}};
3 INT D [2] = {1, 2, 3};
4 int D [] = {1, 2, 3};
5 int [] E = {0,0,0};
6 char C [] = {'a', 'b'};
Error is, and explain
answer:
3
9)
Public class test8 {
Public static void main (String [] args) {
Base b = new subclass ();
System.out.println (B.X);
System.out.println (B.Method ());
}
}
Class base {
INT x = 2;
INT method () {
Return X;
}
}
Class Subclass Extends Base {
INT x = 3;
INT method () {
Return X;
}
}
Point out the operation:
2
3
10)
Abstract class minebase {
Abstract void amethod ();
Static Int i;
}
Public class mine extends minebase {
Public static void main (String Argv []) {
int [] ar = new int [5];
For (i = 0; i System.out.println (Ar [i]); } } Indicates the result of the operation, if the compilation error indicates the cause of the error answer: Compile errors, abstract classes must be rewritten 11) Class base { // void speak () { // System.out.println ("Base"); //} } Class Sub Extends Base { Void Speak () { System.out.println ("Sub"); } } Public class test9 { Public static void main (String Argv []) { Base b = new sub (); B.speak (); } } Indicates the result of the operation, if the compilation error indicates the cause of the error Compile errors, the parent class does not have a similar method. 11) Public class arg { String [] myarg; Public static void main (String Argv []) { Myarg = argv; } Public void amethod () { System.out.println (Argv [1]); } } Indicates the result of the operation, if the compilation error indicates the cause of the error Compile errors, static methods cannot call dynamic properties 12) Public class test { Public static void main (String [] args) { AMETHOD (); } Static void amethod () { Try { System.out.println ("ABCD"); Return; } finally { System.out.println ("123456"); } } } Indicates the result of the operation, if the compilation error indicates the cause of the error answer: ABCD 123456 13) Class xxx { Public static void main (String [] args) { String S1 = "abcde"; String s2 = "abcde"; s1.touppercase (); IF (S1 == S2) System.out.println ("YES"); Else System.out.println ("no"); } } Point out the output result, if the compilation error indicates the cause of the error. answer: YES 14) Public class PAPA { 2. INT i; 3. PAPA (INT J) {i = j;} 4.} 5. 6. Class Child Extends PAPA { 7. Child () {i = 5;} 8. Public static void main (string [] args) { 9. new child (); 10.} 11.} Indicates the output result, if compiling errors point out the cause of the error and the line answer: Compilation error, the parent class constructor is not initialized 15) Public class t { Public static void main (string [] arg) { StringBuffer a = new stringbuffer; "a"); StringBuffer B = New StringBuffer ("B"); Operate (a, b); System.out.println (A "," B); } Static void Operate (StringBuffer X, StringBuffer Y) { X.Append (y); y = x; } } Point out the output result, if the compilation error indicates the cause of the error Output Ab, b 16) String S1 = "abc"; 2. String S2 = S1; 3. String s3 = "abc"; There will be several objects in three statements Answer: 1 16) Public class streq { Public static void main (String Argv []) { Streq s = new streq (); } Private streq () { String s = "marcus"; String S2 = New String ("marcus"); IF (s == s2) { System.out.println ("We Have A Match"); } else { System.out.println ("Not Equal"); } } } Point out the output result, if the compilation error indicates the cause of the error. answer: NOT Equal