One, the choice question
1, access modifier scope from large to small is ()
A. Private-default-protected-public
B.public-default-protected-private
C,private-protected-default-public
D,public-protected-default-private
2, the following () is not a method of object class.
A.clone () b.finalize () c.tostring () D.hasnext ()
3. In Java, the following () interfaces are used to store objects in a key-value manner.
A. java.util.Collection
B.java.util.map
C.java.util.list
D.java.util.set
4, the following procedures to indicate the results of the operation ()
public class Example {
String str = new String ("good");
char[] ch = {' A ', ' B ', ' C '};
public static void Main (string[] args) {
Example ex = new Example ();
Ex.change (Ex.str, ex.ch);
System.out.print (Ex.str + "and");
System.out.print (ex.ch);
}
public void Change (String Str,char ch[]) {
str = ' Test ok ';
Ch[0] = ' g ';
}
}
A. Good and ABC
B. Good and GBC
C. Test OK and ABC
D. Test OK and GBC
Two, fill in the blanks question
5, Java basic data types include ____________________.
Answer: Byte, short, int, long, char, Boolean, float, double
6, Math.Round (11.5) equals ___; Math.Round (-11.5) equals ___.
Answer: The rounding of 11.5 is rounded to 12,-11.5-11 with rounding calculation.
7, the program string str1 = "Hello"; String str2 = "he" +new string ("Llo"); The result of System.out.println (STR1==STR2) is ______.
Answer: false
8, the string is divided into two categories, one is the string constants, using the object of the _ _ _ class, and the other is a string variable, using the object of the _ _ Class representation.
Answer: Constants with string, variable with StringBuffer (thread-safe) or stringbuiler (not thread-safe)
Iii. Questions and Answers
9. What is the difference between an interface and an abstract class?
Answer: 1, the interface of all the methods are abstract, abstract classes can contain specific methods
2. All methods and properties of the interface are public, and the abstract class allows private
3, the implementation of the interface must implement all the methods, and the successor of the abstract class can be implemented, or can not implement
4. Implementing multiple interfaces is similar to implementing multiple inheritance, but an abstract class can only implement single inheritance
10, using recursive method to find 5.
Answer:
public class test{public
static void Main (string[] args) {
System.out.println (JC (5));
public static int-JC (int n) {
if (n== 0 | | n== 1) return
1;
if (n > 1) return
N*JC (n-1);
return 0;
}
}
11, writing multithreaded code has several methods of implementation. Please use the code to illustrate each.
Answer: Two kinds: Inherit thread class and implement Runnable interface.
Class MyThread1 extends thread{public
void Run () {
//do Stuff
}
}
class MyThread2 implements runnable{public
Void Run () {
//do Stuff
}
}
12, Programming Questions: Write an observer mode (first draw the class diagram, and then implemented in code).
Answer: (The following image and code are derived from the network, use the source) Observer mode class diagram:
Code implementation:
Abstract theme Public
interface Subject
{public
void Attach (Observer Observer);
public void Detach (Observer Observer);
void Notifyobservers ();
}
Specific topics public
class ConcreteSubject implements Subject
{public
void Attach (Observer Observer)
{
OBSERVERS.ADD (Observer);
}
public void Detach (Observer Observer)
{
observers.remove (Observer);
}
public void Notifyobservers ()
{for
(Observer observer:observers) {
}
}
private list< Observer> observers = new arraylist<observer> ();
}
Abstract Observer public
interface Observer
{
void update ();
}
Specific observer public
class Concreteobserver implements Observer
{public
void update ()
{
// DoUpdate
}
}
Iv. Selected Questions
A 1 billion-record text file that has been sorted by keyword to store, design algorithms, and customers to quickly find a record of the specified keyword from the file.