100 examples and answers of java classic multiple choice questions

100 examples and answers of java classic multiple choice questions

1. The file extension of the source program written in the Java language is ( ).
(A).class (B).java (C).cpp (D).txt
2.Set int a=-2, then the value of the expression a>>>3 is ( ).
(A) 0 (B) 3 (C) 8 (D) -1
3. If the definition of the array is int[] a = new int[3], then the following reference to the array element is wrong ( ).
(A)a[0]; (B)a[a.length-1];
(C)a[3]; (D)int i=1; a[i]
; It is possible to have two functions with the same name in a class definition, this phenomenon is called function().
(A) Encapsulation (B) Inheritance
(C) Coverage (D) Overloading
5. The role of the constructor in the class definition is ( ).
(A) Protect member variables (B) Read member variables of the class
(C) Describe the characteristics of the class (D) Initialize member variables6
. Which of the following keywords is not used for exception handling statements ( ).
(A) try (B) break
(C) catch (D) finally
7.The relationship between classes and objects is ( ).
(A) A class is an abstraction of an object (B) An object is an abstraction of a class
(C) An object is a subclass of a class (D) A class is a concrete instance of an object
8. Which of the following is an illegal identifier ( ) in Java.
(A) $persons (B) twoNum
(C) _myVar (D) point
9. Write a method header for a method method of class AB that has no formal parameters and no return value, so that it can be called with the class name AB as a prefix. The method header is in the form of ( ).
(A)static void method( )
(B)public void method( )
(C)final void method( )
(D)abstract void method( )
10.To construct an instance of the ArrayList class, which inherits the List interface, which of the following methods is correct ( ).
(A) ArrayList myList=new Object( )
(B) List myList=new ArrayList( )
(C) ArrayList myList=new List( )
(D) List myList=new List( )
11. Java source files and compiled files The extensions are ( )
(A) .class and .java (B).java and .class
©.class and .class (D) .java and .java
12. In the user-defined Applet subclass of the Java Applet program , it is generally necessary to override the ( ) method of the parent class to complete some drawing operations.
(A) start( ) (B) stop( )
(C) init( ) (D) paint( )
13. For a Java source file, the correct order of import, class definition and package is:
(A) package, import, class (B) class, import, package
(C) import, package, class (D) package, class, import
14. Which of the following is illegal:
(A) int I = 32; (B ) float f = 45.0;
(C) double d = 45.0; (D) char c = 'u'; //Wrong symbol
15.The character code set used by the Java language is D
(A) ASCII (B) BCD
(C) DCB (D) Unicode
16. If a member variable of a class can only be used in the class, the modification that must be used for the member variable is
(A) public (B) protected
(C) private (D) static
17. The correct description of the main method below is
(A) public main(String args[ ])
(B) public static void main(String args[ ])
© private static void main(String args[ ])
(D) void main()
18. Which keyword can add a mutex to the object? ( )
(A) transient (B) synchronized
(C) serialize (D) static
19. The correct statement about the abstract method is ( )
(A) can have a method body (B) can appear in a non-abstract class
(C) is a method without a method body (D) methods in an abstract class are all abstract methods
20. The File class of the java.io package is
(A ) Character stream class (B) byte stream class
(C) object stream class (D) non-stream class
21. The main class in a Java application needs to contain the main method. Which of the following is the correct parameter for the main method? ( )
A. String args B. String args[] C. Char arg D. StringBuffer args[]
22.The output after the execution of the following code segment is ( )
int x=-3; int y=-10;
System.out.println(y%x);
A, -1 B, 2 C, 1 D, 3
23. Which of the following statements about inheritance is correct ( ).
A. Classes in Java only allow single inheritance
B. A class in Java can only implement one interface
C. A class in Java cannot inherit a class and implement an interface at the same time
D. Interfaces in Java only allow single inheritance
24. If there is a definition: byte[] x={11,22,33,-66};
where 0≤k≤3, the wrong reference to the x array element is ()
A) x[5-3]
B) x[ k]
C) x[k+5]
D) x[0]
25.What type of parameter does the paint() method take? ( )
A. Graphics B. Graphics2D C. String D. Color
26.Which of the following is not a primitive data type of Java ()
A, int B, Boolean C, float D, char
27. In Java, a class can define many methods with the same name at the same time. The number, type, or order of formal parameters of these methods are different, and the returned values ​​​​can also be different. This object-oriented program feature is called ()
A) hidden
B) rewritten
C) overloaded
D) Java does not support this feature
28. Which of the following statements about the construction method is correct: ( )
A. A class can have multiple constructors
B. The constructor is called when the class is defined
C. Constructors can only be called by other methods on the object.
D.The construction method can have the same name as the class, or it can be different from the class name
29. When the applet program is executed in the browser, which method in the following options will be executed first ( ).
A. init() B. start() C. destroy() D. stop()
30.Given the following code, which of the following statements about the program is correct? ( )
public class Person{ static int arr[] = new int[5]; public static void main(String a[]) { System.out.println(arr[0]); } }





A. An error will be generated when compiling B. It will be correct when compiling, but an error will be generated when running
C. The output will be zero D. The output will be empty
31. If the following methods are defined, please select the return type of the method ( ).
ReturnType method(byte x, double y)
{ return (short)x/y
2;
}
A, byte B, short C, int D, double

32.Which of the following class definitions are valid abstract class definitions? ( )
A, abstract Animal{abstract void growl();}
B, class abstract Animal{abstract void growl();}
C, abstract class Animal{abstract void growl();}
D, abstract class Animal{abstract void growl( ){System.out.println("growl");};}

33.With the following program fragment, which of the following options cannot be inserted into line 1. ( )
1.
2.public class Interesting{ 3.//do sth 4. } A, import java.awt.*; B, package mypackage; C, class OtherClass{ } D, public class MyClass{ }



  1. Set the following two assignment statements:
    a = Integer.parseInt("12");
    b = Integer.valueOf("12").intValue();
    The following statement is correct ( ).
    A, a is an integer type variable, b is an integer type object. B. a is an integer type object, and b is an integer type variable.
    C, a, and b are all integer-like objects and are equal in value. D, a, and b are all variables of integer type and have equal values.
    35.When writing a Java Applet program, you need to write a ( ) statement at the beginning of the program.
    A. import java.awt.* ; B. import java.applet.Applet ;
    C. import java.io.* ; D. import java.awt.Graphics ;
    36.Which of the following is not a top-level container in Swing? ( )
    A) JApplet B) JTree C) JDialog D) JFrame
  2. In order to make the package ch4 visible in the current program, the statement that can be used is ().
    A) import ch4.; B) package ch4.; C
    ) ch4 import; D) ch4 package;
  3. May I ask which class all exception classes inherit from? ( ).
    A) java.io.Exception B) java.lang.Throwable
    C) java.lang.Exception D) java.lang.Error
    39.The package that needs to be used for basic GUI design in Java is ( ).
    A) java.io B) java.sql C) java.awt D) java.rmi
  4. Which of the following events is triggered when the mouse is clicked or dragged? ( )
    A) KeyEvent B) ActionEvent C) ItemEvent D) MouseEvent

41. Which of the following is an identifier in Java (A)
A, fieldname B, super C, 3number D, #number
42. Let x = 1, y = 2, z = 3, then the expression y+=z---/ ++ The value of x is ( ).
A. 3 B. 3. 5 C. 4 D. 5
43. What is the value of count after the following code segment is executed ( )
int count = 1;
for (int i = 1; i <= 5; i++) { count += i; } System.out.println(count); A, 5 B, 1 C, 15 D, 16 44, write the method header for a method method with no formal parameters and no return value in class AB, so that the class name is used AB can be used as a prefix to call it, and the method header is in the form of (). A. static void method( ) B. public void method( ) C. final void method( ) D. abstract void method( ) 45. The result after the execution of the following program segment is ( ). String s = new String(“abcdefg”); for (int i=0; i<s.length(); i+=2){ System.out.print(s.charAt(i)); } A) aceg B ) ACEG C) abcdefg D) abcd













46. ​​After the following program segment is executed, the value of b is ( ).
Integer integ = new Integer(9);
boolean b = integ instanceof Object;
A) 9 B) true C) 1 D) false
47.Which statement about for loop and while loop is correct? ( )
A.The while loop judges first and then executes, and the for loop executes first and then judges.
B.The judgment condition of the while loop is generally the result of the program, and the judgment condition of the for loop is generally the result of the non-program
C. The two cycles cannot be replaced at any time
D. There must be a loop body in both loop structures, and the loop body cannot be empty
48. Which statement about the memory occupied by object members is correct? ( )
A.Objects of the same class share the same memory
B. Objects of the same class use different memory segments, but static members share the same memory space
C. Object methods do not occupy memory
D. None of the above is true
49.The correct statement about inheritance is: ()
A. The subclass will inherit all the properties and methods of the parent class.
B. The subclass will inherit the non-private properties and methods of the parent class.
C. The subclass only inherits the public methods and properties of the parent class
D. The subclass only inherits the methods of the parent class, not the properties
50. The relationship between overriding and overloading is ()
A. Overriding can only occur between the parent class and the subclass, while overloading can occur in the same class.
B. Overridden methods can have different names, but overloaded methods must have the same name
C. Final modified methods can be overridden, but cannot be overloaded
D.Overriding and overloading are the same thing
51. Which of the following import commands can provide us with classes for writing network applications ()
A. import java.sql.; B. import java.util.; C.
import java.io. ; D. import java.net. ;
52. If the layout of the container component p is BorderLayout, then add a button b under p, the statement that should be used is ( ) A
, p.add(b); B, p .add(b,"North");
C, p.add(b, "South"); D, b.add(p, "North");
53. The default layout manager of the Frame object is ( )
A, FlowLayout B, BorderLayout
C, CardLayout D, null
54. If you need to read data from a file, which class of object can you create in the program ( )
A, FileInputStream B, FileOutputStream
C, DataOutputStream D, FileWriter
55, the following The program creates a file output stream object to output data to the file test.txt. Assuming that the file test.txt does not exist in the current directory of the program, after compiling the following program Test.java, run the program 3 times, the file The content of test.txt is ( ).
import java.io.*;
public class Test {
public static void main(String args[]) { try { String s="ABCDE"; byte b[]=s.getBytes(); FileOutputStream file=new FileOutputStream("test.txt",true); file.write( b); file.close(); } catch(IOException e) { System.out.println(e.toString()); } } } A) ABCABC B) ABCDE C) Test D) ABCDE ABCDE ABCDE 56. Compile Java Application source program files will generate corresponding bytecode files, and the extensions of these bytecode files are ( ). A. java B. .class C. html D. .exe 57. Suppose x = 1, y = 2, z = 3, then the value of the expression y+=z--/++x is ( ). A. 3 B. 3. 5 C. 4 D. 5 58. What is not allowed as the access control character of the class and class members is (). A. public B. private C. static D. protected






















59. Write a method header for a method method of class AB that has no formal parameters and no return value, so that it can be called using the class name AB as a prefix. The method header is in the form of ( ).
A. static void method( ) B. public void method( )
C. final void method( ) D. abstract void method( )

60.Which of the following statements about the selection structure is true? ( )
A.The if statement and the else statement must appear in pairs
B. The if statement can have no else statement corresponding to
C. A break statement must be used in each case statement in the switch structure
D. There must be a default statement in the switch structure

61.The difference between a while loop and a do...while loop is: ( )
A. There is no difference, the two structures have the same effect in any case
B. The while loop is more efficient than the do...while loop
C. The while loop loops first and then judges, so the loop body is executed at least once.
D. The do...while loop loops first and then judges, so the loop body is executed at least once

62.Which statement about for loop and while loop is correct? ( )
A.The while loop judges first and then executes, and the for loop executes first and then judges.
B.The judgment condition of the while loop is generally the result of the program, and the judgment condition of the for loop is generally the result of the non-program
C. The two cycles cannot be replaced at any time
D. There must be a loop body in both loop structures, and the loop body cannot be empty

63.Which of the following modifiers has nothing to do with access control is ( )
A. private B.public
C.protected D.final

64.The meaning of void: ( )
A. The method does not return a value B. The method body is empty
C. Doesn't make sense D. Must be used when defining a method

65.return statement: ( )
A. The method can only return a value B. The method must contain
C. There can be multiple returns in the method D.cannot be used to return an object

66.Which statement about the memory occupied by object members is correct? ( )
A.Objects of the same class share the same memory
B. Objects of the same class use different memory segments, but static members share the same memory space
C. Object methods do not occupy memory
D. none of the above is right

67.Which of the following statements is correct?
A.Objects can be created without defining a class
B. The object must have properties and methods
C. Attributes can be simple variables or an object
D. Attributes must be simple variables

68.Which of the following statements is correct? ( )
A. A program can contain multiple source files
B. There can only be one class in a source file
C. There can be multiple public classes in a source file
D. A source file can only be used by one program

69.Which statement about the method main() is true? ( )
A.The method main() can only be placed in the public class
B The header definition of main() can be changed arbitrarily according to the situation
C. A class may not have a main() method
D. All object creation must be placed in the main() method

70.When is the constructor called? ( )
A. when creating an object B. when defining a class
C. when using an object's method D. when using an object's attribute

71.Abstract method: ( )
A, can have a method body
B, can appear in a non-abstract class
C, is a method without a method body
D, the methods in an abstract class are all abstract methods

72.The correct statement about inheritance is: ()
A. The subclass will inherit all the properties and methods of the parent class.
B. The subclass will inherit the non-private properties and methods of the parent class.
C. The subclass only inherits the public methods and properties of the parent class
D. The subclass only inherits the methods of the parent class, not the properties

73.Which statement about constructors is correct? ( )
A. A class can only have one constructor
B. A class can have multiple constructors with different names
C. The constructor has the same name as the class
D. The constructor must be defined by itself, and the constructor of the parent class cannot be used

74.this and super:
A, both can be used in the main() method
B, both refer to a memory address
C, cannot be used in the main() method
D, have the same meaning

75.The correct statement about super is:
A, refers to the memory address of the current object
B, refers to the memory address of the parent object of the current object
C, refers to the parent class of the current object
D, can be used in the main() method

76.The relationship between overriding and overloading is ()
A. Overriding can only occur between the parent class and the subclass, while overloading can occur in the same class.
B. Overridden methods can have different names, but overloaded methods must have the same name
C. Final modified methods can be overridden, but cannot be overloaded
D. Overriding is the same thing as overloading

77.Which is correct about the interface? ( )
A. To implement an interface, all methods of the interface must be implemented
. B. A class can implement only one interface
C. There can be no inheritance relationship between interfaces
D. Interface and abstract class are the same thing

78.Exceptions include which of the following? ( )
A.Unforeseen circumstances encountered during program execution
B. A syntax error in the program
C. Compilation error of the program
D. All of the above

79.For statements that have been defined that may throw exceptions, when programming: ()
A. You must use try/catch statements to handle exceptions, or use throws to throw them
B. If the program fails, the exception must be handled with a try/catch statement
C. Can be ignored
D. Can only be processed with try/catch statements

80.The difference between a character stream and a byte stream is ( )
A. The former has a buffer, the latter has no
B. The former is block reading and writing, the latter is byte reading and writing
C. There is no difference between the two and can be used interchangeably
D. The number of bytes read and written each time is different

81.Which of the following streams is not a byte stream ( )
A. FileInputStream
B.BufferedInputStream
C. FilterInputStream
D. InputStreamReader

82. In the object-oriented method, the way one object requests another object to serve it is by sending ()
A, call statement
B, command
C, password
D, message
83. Java language has many advantages and characteristics, the following options Among them, which one reflects the characteristics of the parallel mechanism of Java programs: ()
A, safety
B, multi-threading
C, cross-platform
D, portability
84. The steps of writing and running a Java applet program and writing and running a Java application program are different : ( )
A. Write the source code
B. Write the HTML file to call the applet, save it in the same folder with the extension of .html
C. Compile the process
D. Interpret and execute
85. The character type of Java adopts the Unicode encoding scheme, Each Unicode code occupies ____ bits. ( )
A, 8
B, 16
C, 32
D, 64
86. Regarding the output results of the following program segments, the statement is correct: (D The default initial value of the basic type of numerical data is 0)
public class MyClass{ static int i; public static void main(String argv[]){ System.out.println(i); } } A. There is an error, the variable i is not initialized.






B, null
C, 1
D, 0
87. The execution result of the following code is: ( )
public class Test3{ public static void main(String args[]){ System.out.print(100%3); System.out. print(“,”); System.out.println(100%3.0); } } A, 1,1 B, 1,1.0 C, 1.0,1 D, 1.0,1.0 88. The output of the following program segment is: ( ) void complicatedExpression(){ int x=20, y=30; boolean b; b=x>50&&y>60||x>50&&y<-60||x<-50&&y>60||x<-50&&y<- 60; System.out.println(b); } A, true B, false C, 1 D, 0 89. Given the following code fragment: ( ) if(x>0){System.out.println("first" );}























else if(x>-3){ System.out.println("second");}
else {System.out.println("third");}
What range will the string "second" be printed when x is in?
A , x>0
B, x>-3
C, x<=-3
D, x<=0 &&x>-3
90. To declare a variable as a temporary variable, which of the following modifiers should be used? ()
A, protected
B, provate
C, transient (temporary variable)
D, volatile (shared variable)
91. In Java, a class can define many methods with the same name at the same time, the number, type
or order of the formal parameters of these methods Each is different, and the returned value can also be different. This object-oriented program feature is called: ()
A, hide
B, cover
C, overload
D, Java does not support this feature
92. If you want to throw an exception, apply Which of the following clauses? ()
A, catch
B, throws
C, try
D, finally
93. When using interface to declare an interface, only the ____ modifier can be used to modify the interface. ( )
A, private
B, protected
C, private protected
D, public
94 .下列代码的输出结果是 : ( )
class Parent{
void printMe() {
System.out.println(“parent”);
}
};
class Child extends Parent {
void printMe() {
System.out.println(“child”);
}
void printall() {
super.printMe();
this.printMe();
printMe();
}
}
public class Test_this {
public static void main(String args[]) {
Child myC=new Child();
myC.printall();
}
}
A、parent
child
child
B、parent
child
parent
C、parent
child
D、编译错误
95. Which of the following streams should be used to process the read content and then output it? ( )
A, File stream
B, Pipe stream
C, Random stream
D, Filter stream
96. In order to realize communication between multiple threads, which of the following streams is appropriate? ( )
A. Filter stream
B. File stream
C. Random access stream
D. Piped stream
97. The difference between Swing and aWT does not include: ( )
A. Swing is a lightweight component implemented in pure Java
B. Swing has no native code
C. Swing does not rely on the support of the operating system
D. Swing supports the graphical user interface
98. When writing a Java applet program, if you need to respond to and process events that occur, you generally need to
write a ____ statement at the beginning of the program. ()
A. import java.awt.; B.
import java.applet.;
C.
import java.io .;
D. import java.awt.event.;
99.
The basic principles of annotations do not include: ()
A. annotations It should increase the clarity of the code
B. The comments should be concise
C. Write comments before writing code
D. Try to add comments to each statement
100. Multiple stream types are defined in the java.io package to realize input and output functions, which can be classified from different angles, divided by function For: ( )
A. Input stream and output stream (direction)
B. Byte stream and character stream (content)
C. Node stream and processing stream (division of labor)

1 2 3 4 5-----6 7 8 9 10
B C C D D------B A D A C
11 12 13 14 15-------16 17 18 19 20
B D A D D------- C B B D D
21 22 23 24 25------ 26 27 28 29 30
B A A C D -------B C A B C
31 32 33 34 35------ 36 37 38 39 40
D C D A B------- B A B C D
41 42 43 44 45------- 46 47 48 49 50
A A D A A -------B B B B A
51 52 53 54 55------ 56 57 58 59 60
D C B A D ---------B A C A B
61 62 63 64 65------ 66 67 68 69 70
D B D A C -------B C A C A
71 72 73 74 75-------- 76 77 78 79 80
C B C C B---------A A A A D
81 82 83 84 85-------- 86 87 88 89 90
D D B B B---------- D B B D C
91 92 93 94 95--------- 96 97 98 99 100
C B D A D ----------D D D D C

Guess you like

Origin blog.csdn.net/Serendipitysyn/article/details/129932793