Java test exercises, java Test

Source: Internet
Author: User

Java test exercises, java Test

Multiple choice questions (50 questions in total, 1.5 points for each question, a total of 75 points. If multiple choice questions are incomplete or incorrect, no score is obtained .)
1. The following are object-oriented features (C, D ). (Two items)
A) Heavy Load
B) rewrite
C) Encapsulation
D) Inheritance

2. The output of the following code is (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 (p. name );
}
}
A) Output: Person
B) No output
C) Compilation Error
D) running error

3. Which of the following statements is true when the super and this keywords are used? ()
A) use super () in the subclass constructor to display the constructor that calls the parent class. super () must be written in the first line of the subclass constructor; otherwise, compilation fails.
B) super () and this () do not have to be placed in the first line of the constructor.
C) this () and super () can appear in a constructor at the same time.
D) this () and super () can be used in the static environment, including static methods and static statement blocks.

4. Which of the following statements about encapsulation is true? (D)
A) Only methods in one class can be encapsulated, and attributes cannot be encapsulated.
B) if the subclass inherits the parent class, the subclass can still directly call the encapsulated methods in the parent class.
C) encapsulation is of little significance, so try not to use it during encoding.
D) the main function of encapsulation is to hide internal implementation details and enhance program security.

5. Which of the following statements about inheritance is false? ()
A) Inheritance in Java allows A subclass to inherit multiple parent classes.
B) The parent class is more universal and the Child class is more specific.
C) Inheritance in Java is passed.
D) The constructor in the parent class is recursively called when the child class is instantiated.

6. The running result of the following program is (D)
Class Person {
Public Person (){
System. out. println ("this is 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 (this. name );
}
}
A) this is a Person
This is a teacher
Tom
B) this is a teacher
This is a Person
Tom
C) running error
D) There are two compilation errors.

7. Which of the following statements is false ()
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. attributes can call all non-private attributes of the parent class.
D) The this and super keywords can appear in the same constructor.

8. Which of the following statements about the final keyword is false? (A, C) (two items)
A) final is A modifier in java. It can be used to modify classes, interfaces, abstract classes, methods, and attributes.
B) The final modified class cannot be inherited.
C. The final modification method cannot be overloaded.
D. The final variable cannot be assigned another value.

9. The access modifier ranges 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 the Object class Method
A) clone ()
B) finalize ()
C) toString ()
D) hasNext ()

11. polymorphism is manifested in ()
A) rewrite
B) Abstraction
C) Inheritance
D) Encapsulation

12. Which of the following statements about overload is false? (B)
A) method overloading can only happen inside A class.
B) The constructor cannot be overloaded.
C) The method name must be the same for heavy load, and the parameter list must be different.
D) the return value type of a method is not a condition for distinguishing method overloading.

13. No error will occur when the following (D) is 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. Which of the following statements about abstract classes is true? (C)
A) The abstract class has no constructor.
B) abstract classes must provide abstract methods.
C) classes with abstract methods must be abstract classes.
D) abstract classes can be directly instantiated using the new keyword.

15. Which of the following statements about the interface is false? (D)
A) No constructor is provided for the interface.
B) the methods in the interface are modified using public and abstract by default.
C) attributes in the interface are modified using public, static, and final by default.
D) interface does not allow many inheritance

16. The following code describes ()
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) Row 3 error. No variable value assigned
B) row 2nd error. The method has no modifier.
C) Row 4th error. No interface implementation methods
D. There is no way to implement the 3rd rows error.

17. The descriptions of interfaces and abstract classes are (B, C) (two items)
A) The abstract class has no constructor.
B) the interface has no constructor.
C) abstract classes do not allow many inheritance
D) methods in the interface can have method bodies

18. Which of the following statements is false? (C)
A) abstract: Class, interface, and method can be modified.
B) abstract modified classes are mainly used for inheritance.
C) abstract variable can be modified
D) the class of abstract modification. Its subclass can also be abstract modified.

19. Which of the following statements are true? (B)
A) method rewriting is applied inside A class.
B) method Overloading is irrelevant to the return value type.
C) The constructor cannot be overloaded.
D) The constructor can be rewritten.

20. The following program running result is ()
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) running error, no output

21. Which of the following statements about exceptions is false? (C)
A) exceptions are classified into Error and Exception
B) Throwable is the parent class of all Exception classes.
C) Exception is the parent class of all Exception classes.
D) Exceptions include exceptions other than RuntimeException and RuntimeException.

22. In the try-catch-finally statement block, which of the following can be used with finally separately? (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 ){
Try {
Return a + B;
} Catch (Exception e ){
System. out. println ("catch statement block ");
} Finally {
System. out. println ("finally statement block ");
}
Return 0;
}
Public static void main (String [] args ){
Demo demo = new Demo ();
System. out. println ("And yes:" + demo. add ));
}
}
A) compilation exception
B) finally statement block and is: 43
C) and are: 43 finally statement Blocks
D) catch statement block sum: 43

24. Which of the following statements are incorrect? (D)
A) try block cannot be omitted.
B) Multiple catch blocks can be used.
C) The finally block can be omitted.
D) The catch Block and finally block can be omitted at the same time.

25. Which of the following statements about custom exceptions are true? (C)
A) custom exceptions must inherit exceptions.
B) custom exceptions can be inherited from errors.
C) custom exceptions can be used to clearly locate the error location and provide detailed error information.
D) a wide range of exception classes have been provided in the program. It is meaningless to use custom exceptions.

26. The following program running result is (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 ("OPERATOR:" + demo. div (9, 0 ));
}
}
A) The Exception finally operator is: 0
B) The ArithmeticException finally operator is: 0
C) The finally operator is: 0
D) Compilation Error

27. Which of the following statements about TCP and UDP are true? (D)
A) TCP cannot provide data reliability
B) UDP ensures database Reliability
C) TCP data transmission efficiency is higher than UDP
D) UDP data transmission efficiency is higher than TCP

28. In Java, which of the following statements about the constructor is true is (D ). (Select one)
A) the class must display the definition constructor.
B) The return type of the constructor is void.
C) The constructor and class have the same name and cannot contain any parameters.
D) one class can define multiple constructors.

29. According to the following code,
String s = null;
The NullPointerException (A, C) is 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, which of the following statements about the HashMap class is false is (B ).
A) HashMap uses keys/worth to save data
B) HashMap can ensure the order of Elements
C) HashMap allows null to be used as a key.
D) HashMap allows null to be used as a value.

31. Which of the following statements about the super keyword in java is false? (B)
A) The super keyword refers to the reference of its parent class object within the subclass object.
B) The super keyword can refer not only to the direct parent class of the Child class, but also to the parent class of the Child parent class.
C) subclass can use the super keyword to call the method of the parent class.
D) subclass can use the super keyword to call attributes of the parent class.

32. In Java, the following code (A) correctly creates an 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 ability to locate local file systems and perform basic operations on files, directories, and their attributes.
A) FileInputStream
B) FileReader
C) FileWriter
D) File

34. The collection classes in Java include ArrayList, sorted list, And HashMap. Which of the following statements about the collection classes is false? (C) (select one)
A) Both ArrayList and javaslist implement the List interface.
B) The access speed of the ArrayList is faster than that of the sorted list.
C) when adding or deleting elements, ArrayList performs better.
D) HashMap implements the Map interface, which allows key and value objects of any type 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.
The connection statement to the data source is:
Connection con = DriverManager. getConnection ("jdbc: odbc: news ");
"N ews" in the URL Connection indicates (C) (select one)
A) Name of the table in the database
B) database server machine name
C) Data Source Name
D) User Name

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

37. In Java, the following (B) interfaces store objects as key-value pairs.
A) java. util. Collection
B) java. util. Map
C) java. util. List
D) java. util. Set

38. Which of the following statements about Object serialization is true? (C, D) [two items]
A) You can use FileOutputStream to transmit objects.
B) Use PrintWriter to transmit objects.
C) use the ObjectOutputStream class to store objects and use the ObjectInputStream class to read objects.
D) the class to which the object is serialized must implement the Serializable interface.

39. In Java, (A) class can be used to create objects in the Linked List data structure.
A) Upload list
B) ArrayList
C) Collection
D) HashMap

40. Analyze the following Java code. Its running result is (C ).
Import java. io .*;
Public class B {
Public static void main (string [] args ){
Int I = 12;
System. out. println (I + = I-= I * = I );}}

(A) 100
B) 0
C.-120
D) The program cannot be compiled.

41. The procedure for using JDBC transactions is (C, A, B, D) (Multiple choices)
A) Automatic transaction commit Method for canceling Connection
B) An abnormal rollback transaction occurs.
C) obtain the Connection object
D. Submit the transaction after the operation is completed.

42. Which of the following statements about JDBC transactions is false? (B)
A) JDBC transactions are A type of JAVA transactions.
B) JDBC transactions belong to the container transaction type
C) JDBC transactions can ensure operation integrity and consistency
D) JDBC transactions are initiated by connections and controlled by connections.

43. to update data through A rolling result set, which of the following is true?
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 is the input parameter and the second is the output parameter. Which of 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. Which of the following statements is true? (B)
A) CallableStatement is the parent interface of PreparedStatement.
B) PreparedStatement is the parent interface of CallableStatement.
C) CallableStatement is a subinterface of Statement.
D) PreparedStatement is the parent interface of Statement.

46. If you want to delete A book (bookName) in the book table is A "java" record, which of the following code is correct?
String SQL = "delete from book where bookName = ?";
PreparedStatement pst = con. preparedStatement (SQL );
______________________________
Pst.exe cute ();
A) pst. setString (1, "java ");
B) pst. setString (0, "java ");
C) pst. setInt (0, "java ");
D) The preceding options are incorrect.

47. Obtain the first row of data of the ResutlSet object rst. Which of the following statements is true? (B)
A) rst. hashNext ();
B) rst. next ();
C) rst. first ();
D) rst. nextRow ();

48. Which of the following statements can correctly obtain the result set are (AD) (Multiple choices)
A) Statement sta = con. createStatement ();
ResultSet rst=sta.exe cuteQuery ("select * from book ");
B) Statement sta = con. createStatement ("select * from book ");
ResultSet rst=sta.exe cuteQuery ();
C) PreparedStatement pst = con. preparedStatement ();
ResultSet rst1_pst.exe cuteQuery ("select * from book ");
D) PreparedStatement pst = con. preparedStatement ("select * from book ");
ResultSet rst1_pst.exe cuteQuery ();

49. Which of the following is responsible for establishing a connection to the database? (D)
A) Statement
B) PreparedStatement
C) ResultSet
D) DriverManager

50. The order in which JDBC is used to connect to the database is (B, A, D, C, E) (Multiple choices)
A) load the driver
B) import the driver package
C) Send and process SQL statements
D) database connection
E. Close the connection.

 

Ii. Short answer questions (each score is 5 points, totally 25 points)

1. What does it mean to declare a class as final in java? (No score)

A: final is the final meaning. final can be used to define variables, methods, and classes but has different meanings. Classes declared as final cannot be inherited.

1. Can the constructor of the parent class overwrite the quilt class )?

A: The constructor of the parent class cannot overwrite the quilt class, because the class names of the parent class and subclass cannot be the same.

2. Tell us the difference between String and StringBuffer.

A: The object defined by the String class is a String used to store "fixed length.

The StringBuffer class defines an object that is used to store "variable length" strings.

3. If there are two classes A and B (note that they are not interfaces) and you want to use the functions of these two classes at the same time, how do you compile the C class?

A: Because classes A and B are not interfaces, they cannot be directly inherited. However, they can be defined as parent and child classes, then Class C can implement the functions of Class A and Class B. If A is the parent class of B and B is the parent class of C, C can implement the functions of A and B.

4. Combine Java video Lesson5 (multithreading) to analyze the differences between sleep () and wait () methods.

A: Sleeping refers to the sleep () method used to suspend the thread temporarily. After sleep, the thread enters the ready state.

Waiting: If the wait () method is called, the thread is in the waiting state. Used when two or more threads run concurrently.

5. Let's talk about your understanding of abstract classes and interfaces.

A: the purpose of defining an abstract class is to provide a general form that can be shared by its subclass. The subclass can expand the abstract class according to its own needs. The abstract class cannot be instantiated. The abstract method does not have a function body. The abstract method must be provided in the subclass. specific implementation. He uses extends to inherit.

Interface: an interface allows a class to inherit from Several Interfaces. A Java program can only inherit one class at a time, but can implement several interfaces. The interface cannot have any specific method, APIS can also be used to define a group of constants that can be used by classes. The implementation method is interface.

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: info-contact@alibabacloud.com 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.