Java Face test questions:

Source: Internet
Author: User
Tags finally block object serialization

Select the question (a total of 50 questions, each topic 1.5 points, a total of 75 points. The choice of multiple choice or wrong is not scored. )
1. The following belong to the object-oriented feature (C,D). (Two items found)
A) overloading
B) rewrite
C) package
D) Inheritance

2. The following code runs the output (C)
public class person{
Private String name= "person";
int age=0;
public class Child extends person{
public String grade;
public static void Main (string[] args) {
Person p = new Child ();
System.out.println (;
A) Output: Person
B) No output
C) Compilation Error
D) Run Error

3. When using the super and the This keyword, the following description is correct (A)
A) using super () in the subclass construction method to display the constructor method that calls the parent class, super () must be written in the first row of the subclass construction method, otherwise the compilation does not pass
B) Super () and this () do not have to be placed within the first line of the constructor method
C) This () and super () can appear in one constructor at a time
D) This () and super () can be used in a static environment, including static methods and static statement blocks

4. The following description of the package is correct (D)
A) Only methods in one class can be encapsulated and attributes cannot be encapsulated
B) If the subclass inherits from the parent class, the subclass can still call directly to the method that is encapsulated in the parent class.
C) encapsulation is of little significance, so try not to use it when coding
D) The main role of the package is to hide internal implementation details, enhance the security of the program

5. The following description of the inheritance is wrong (a)
A) Inheritance in Java allows a subclass to inherit multiple parent classes
B) The parent class is more generic and the subclass more specific
C) Inheritance in Java has a transitive nature
D) Recursive invocation of a constructor method in a parent class when instantiating a subclass

6. The following program runs as a result (D)
Class person{
Public person () {
System.out.println ("This was a person");
public class Teacher extends person{
Private String name= "Tom";
Public Teacher () {
System.out.println ("This is a teacher");
Super ();
public static void Main (string[] args) {
Teacher Teacher = new Teacher ();
System.out.println (;
A) This was a person
This is a teacher
B) This is a teacher
This was a person
C) Run Error
D) There are two errors in compiling

7. The following statement is wrong ()
A) Super. Method () can call all non-private methods of the parent class
B) Super () can call all non-private constructors of the parent class
C) Super. Property can call all non-private properties of the parent class
D) The This and Super keywords can appear in the same constructor

8. The following statement about the final keyword is wrong (a,c) (two items)
A) final is a modifier in Java that can be decorated with classes, interfaces, abstract classes, methods, and properties
B) The final modified class must not be inherited
C) The final modified method cannot be overloaded
D) Final modified variables are not allowed to be re-assigned

9. The access modifier is scoped from large to small (D)
A) Private-default-protected-public
B) public-default-protected-private
C) Private-protected-default-public
D) public-protected-default-private

10. The following (D) is not a method of the object class
A) Clone ()
B) Finalize ()
C) toString ()
D) Hasnext ()

11. Polymorphic manifestations are (a)
A) rewrite
B) Abstract
C) Inheritance
D) Encapsulation

12. The following description of the overload is incorrect (B)
A) method overloads can only occur inside a class
B) Construction methods cannot be overloaded
C) overloading requires method name is the same, parameter list is different
D) The return value type of the method is not a condition for differentiating method overloads

13. The following (D) is not error-added to Computerbook
Class book{
protected int GetPrice () {
return 30;
public class Computerbook extends book{
A) protected float GetPrice () {}
B) protected int getprice (int page) {}
C) int getprice () {}
D) public int getprice () {return 10;}

14. The following description of the abstract class is correct (C)
A) Abstract class No construction method
B) Abstract classes must provide abstract methods
C) classes with abstract methods must be abstract classes
D) Abstract classes can be instantiated directly from the New keyword

15. The following description of the interface error has (D)
A) The interface does not provide a construction method
B) methods in the interface by default using public, abstract decoration
C) properties in the interface default to public, static, final decoration
D) interface does not allow multiple inheritance

16. The following code, which is described correctly with (a)
Interface idemo{
public static final String name;1
void print (); 2
public void GetInfo (); 3
Abstract class Person implements Idemo{4
public void print () {
A) 1th row error, no value assigned to variable
B) 2nd line error, method without modifier
C) Line 4th error, no full method of implementing interface
D) 3rd line error, no method implementation

17. Interfaces and abstract class descriptions are correct (b,c) (two items)
A) Abstract class has no constructors
B) The interface has no constructors
C) abstract class does not allow multiple inheritance
D) methods in the interface can have a method body

18. The following description is incorrect (C)
A) Abstract can modify classes, interfaces, methods
B) Abstract modified classes are primarily used for inherited
C) abstract can modify variables
D) An abstract modified class whose subclasses can also be abstract-modified

19. The following descriptions are correct (B)
A) The rewrite of the method is applied inside a class
B) The overloads of the method are independent of the return value type
C) Construction methods cannot be overloaded
D) Construction methods can be overridden

20. The following program runs the result (a)
public class Test extends father{
Private String name= "test";
public static void Main (string[] args) {
Test test = new test ();
System.out.println (Test.getname ());
Class father{
Private String name= "father";
Public String GetName () {
return name;
A) father
B) test
C) Compilation Error
D) Run error, no output

21. The following description of the exception is incorrect (C)
A) exceptions are divided into error and exception
B) Throwable is the parent class of all exception classes
C) exception is the parent class for all exception classes
D) exception including anomalies outside of RuntimeException and RuntimeException

22. In the try-catch-finally statement block, the following can be used alone with finally (B)
A) Catch
B) Try
C) throws
D) Throw

23. The following code runs the result (B)
public class demo{
public int Add (int a,int b) {
return a+b;
}catch (Exception e) {
SYSTEM.OUT.PRINTLN ("catch statement block");
SYSTEM.OUT.PRINTLN ("finally statement block");
return 0;
public static void Main (string[] args) {
Demo Demo = new Demo ();
System.out.println ("and is:" +demo.add (9,34));
A) Compile exception
B) finally statement block and yes: 43
C) and yes: the finally statement block
D) Catch statement block and yes: 43

24. The following descriptions are incorrect (D)
A) Try block can not be omitted
B) Multiple catch blocks can be used
C) finally block can be omitted
D) Catch block and finally block can be omitted at the same time

25. The following description of the custom exception is correct (C)
A) Custom exceptions must inherit exception
B) Custom exceptions can inherit from error
C) Custom Exceptions can more clearly locate the location of the exception error and give detailed error information
D) A rich exception class has been provided in the program, and using custom exceptions is meaningless

26. The following program runs the result (D)
public class Test {
public int div (int a, int b) {
try {
return a/b;
}catch (Exception e) {
System.out.println ("Exception");
}catch (NullPointerException e) {
System.out.println ("ArithmeticException");
catch (ArithmeticException e) {
System.out.println ("ArithmeticException");
} finally {
System.out.println ("finally");
return 0;
public static void Main (string[] args) {
Test demo = new test ();
System.out.println ("Quotient is:" + demo.div (9, 0));
A) Exception finally quotient is: 0
B) ArithmeticException finally quotient is: 0
C) finally quotient is: 0
D) Compile Error

27. The following description of TCP and UDP is correct (D)
A) TCP does not provide the reliability of the data
B) UDP can guarantee the reliability of the database
C) TCP data transfer efficiency higher than UDP
D) UDP data transfer efficiency higher than TCP

28. In Java, the following description of the constructor is correct (D). (Select an item)
A) class must display the definition constructor
B) The return type of the constructor is void
C) Constructors and classes have the same name and cannot take any arguments
D) A class can define multiple constructors

29. According to the code below,
String s = null;
The NullPointerException exception (A,C) will be thrown. [Two items]
A) if ((S!=null) & (S.length () >0))
B) if ((S!=null) & & (S.length () >0))
C) if ((S==null) | (S.length () ==0))
D) if ((s==null) | | | (S.length () ==0))

30. In Java, for the description of the HashMap class, the following corruption error is (B).
A) HashMap save data using key/worthwhile form
B) HashMap can guarantee the order of the elements
C) HashMap allows NULL to be used as a key
D) HashMap allows NULL to be used as a value

31. The statement in the following options about the Super keyword in Java is wrong (B)
A) The Super keyword is a reference to an object within a subclass object that refers to its parent class
B) The Super keyword can refer not only to the immediate parent class of a subclass, but also to the parent class of the parent class.
C) Subclasses can invoke the method of the parent class through the Super keyword
D) subclasses can invoke the properties of the parent class through the Super keyword

32. In Java, the following code (a) correctly creates a InputStreamReader object.
A) Inuptstreamreader (New FileInputStream ("1.dat"));
B) Inuptstreamreader (New FileReader ("1.dat"));
C) Inuptstreamreader (New Bufferreader ("1.dat"));
D) Inuptstreamreader ("1.dat");

33. In Java, the (D) class provides the location of the local file system and basic operations on a file or directory and its attributes.
A) FileInputStream
B) FileReader
C) FileWriter
D) File

The collection classes in Java include ArrayList, LinkedList, HashMap, and so on, and the following about the collection class describes the error (C) (select an item)
A) ArrayList and LinkedList both implement the list interface
B) ArrayList access speed is faster than LinkedList
C) when adding and removing elements, the ArrayList performance is better
D) HashMap implements the map interface, which allows any type of key and value object, and allows NULL to be used as a key or value

35. When developing a JDBC application in Java, use the getconnection () method of the DriverManager class
Establish a connection statement with the data source as:
Connection con = drivermanager.getconnection ("Jdbc:odbc:news");
"N ews" in a URL connection means (C) (select an item)
A) name of the table in the database
B) The machine name of the database server
C) name of the data source
D) User name

36. In Java, JDBCAPI defines a set of interfaces and classes that are used to communicate with the database, which are included in the (B) package.
A) Java.lang
B) java.sql
C) Java.util
D) Java.math

In Panax Notoginseng Java, the following (B) interface stores the object in the form of a key _ value pair.
A) java.util.Collection
B) Java.util.Map
C) java.util.List
D) Java.util.Set

38. The following description of object serialization is correct (C,D) [two]
A) use FileOutputStream to transfer objects
B) use PrintWriter to transfer objects
C) Use the ObjectOutputStream class to complete object storage and use the ObjectInputStream class to complete object reads
D) The owning class of the object serialization needs to implement the Serializable interface

39. In Java, the (A) class can be used to create an object of a linked list data structure.
A) LinkedList
B) ArrayList
C) Collection
D) HashMap

40. Analyze the following Java code, which runs as a result (C).
public class b{
public static void Main (string [] args) {
int i=12;
System.out.println (i+=i-=i*=i);}}

A) 100
B) 0
D) The program cannot be compiled

41. The steps to use the JDBC transaction are (C,A,B,D) (multiple selection)
A) Canceling the connection transaction Auto-Submit method
B) An exception rollback transaction occurred
C) Get Connection object

42. The following description of the JDBC transaction is incorrect (B)
A) JDBC transactions are part of a Java transaction
B) the JDBC transaction belongs to the container transaction type
C) JDBC transaction can guarantee the integrity and consistency of operation
D) The JDBC transaction was initiated by connection and controlled by connection

43. To update data through a scrollable result set, the following is correct (a
A) pst=con.preparestatement (SQL, resultset.type_scroll_sensitive,resultset.concur_updatable)
B) pst=con.preparestatement (SQL, resultset.type_scroll_sensitive,resultset.concur_read_only)
C) pst=con.preparestatement (SQL, ResU ltset.type_scroll_sensitive)
D) pst=con.preparestatement (SQL, resultset.concur_updatable)

44. The stored procedure Pro has two parameters, the first one is the input parameter, the second is the output parameter, and the following code is correct (C)
A) callablestatement Cst=con.preparecall ("(Call Pro (?,?))");
B) CallableStatement Cst=con.preparecall ("(Call Pro (?))");
C) CallableStatement Cst=con.preparecall ("{Call Pro (?,?)}");
D) CallableStatement Cst=con.preparecall ("{Call Pro (?,?,?)}");

45. The following description is correct (b)
A) CallableStatement is the parent interface of PreparedStatement
B) PreparedStatement is the parent interface of CallableStatement
C) CallableStatement is the statement sub-interface
D) PreparedStatement is the parent interface of statement

46. To delete the Book table in books (BookName) is the "Java" record, the following code is correct (a
String sql= "Delete from book where bookname=?";
PreparedStatement pst=con.preparedstatement (SQL);
Pst.execute ();
A) pst.setstring (1, "Java");
B) pst.setstring (0, "Java");
C) pst.setint (0, "Java");
D) The above options are not correct

47. Get the first line of data for the Resutlset object RST, the following is correct (B)
A) Rst.hashnext ();
B) ();
C) Rst.first ();
D) Rst.nextrow ();

48. The following can get the result set correctly (AD) (multiple selection)
A) Statement sta=con.createstatement ();
ResultSet rst=sta.executequery ("SELECT * from book");
B) Statement sta=con.createstatement ("SELECT * from book");
ResultSet Rst=sta.executequery ();
C) PreparedStatement pst=con.preparedstatement ();
ResultSet rst=pst.executequery ("SELECT * from book");
D) PreparedStatement pst=con.preparedstatement ("SELECT * from book");
ResultSet rst=pst.executequery ();

49. The following is responsible for establishing a connection with the database is (D)
A) Statement
B) PreparedStatement
C) ResultSet
D) DriverManager

50. The order in which the database is connected using JDBC is (b,a,d,c,e) (multiple selection)
A) Load Driver
B) Import the driver package
C) Send and process SQL statements
D) connections built into the database
E Close Connection

Second, Jane answers (each 5 points, Total - points)

1. What does it mean if you declare a class as final in Java? (regardless of the points)

A: Final is the ultimate meaning, final can be used to define variables, methods, and classes but with different meanings, a class declared final cannot be inherited.

1. Can the parent class override (override) The construction method of the quilt class?

A: The parent class's construction method cannot be overridden by the quilt class, because the class name of the parent class and subclass is not the same.

2. Please tell me the difference between string and StringBuffer.

A: The object defined by the string class is a string that holds "fixed length".

The object defined by the StringBuffer class is a string that holds "variable length".

3, if there are two classes A, B (note is not an interface), you want to use the function of the two classes at the same time, then how would you write this class C?

A : Because Class A, B is not an interface, so it is not directly inherited, but you can define a, B class as a parent-child class, then Class C can achieve a, class B functions. If a is the parent of B and B is the parent of C, then C can realize the function of a and B.

4, combined with Java video Lesson5 (multithreading), analyze the difference between the sleep () and wait () methods.

Answer: Sleeping sleep means: The sleeping () method is used to temporarily abort the execution of the thread. After sleep, the thread enters the ready state.

Waiting wait: If the Wait () method is called, the thread will be in a wait state. Used when two or more threads are running concurrently.

5. Talk about your understanding of abstract classes and interfaces.

A: The purpose of defining an abstract class is to provide a generic form that can be shared by its subclasses, subclasses can extend abstract classes according to their needs, abstract classes cannot be instantiated, abstract methods have no function bodies, and abstract methods must give concrete implementations in subclasses. He used extends to inherit.

Interface: An interface allows a class to inherit from several interfaces, a Java program can inherit only one class at a time, but several interfaces may be implemented, interfaces cannot have any specific methods, and interfaces can be used to define a set of constants that can be used by a class. Its implementation is interface to achieve.

Copyright notice: I feel like I'm doing a good job. I hope you can move your mouse and keyboard for me to order a praise or give me a comment, under the Grateful!_____________________________________________________ __ Welcome reprint, in the hope that you reprint at the same time, add the original address, thank you with

Java Face test questions:

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.