1. the scope is public, private, and protected.
A: The differences are as follows:
Scope: current class, same package, Child class, other package
Public √
Protected √ ×
Friendly √ ××
Private √ ×××
The default value is friendly when no data is written.
2. What is the difference between arraylist and vector? What is the difference between hashmap and hashtable?
A: arraylist and vector are mainly used in two aspects.
1. Synchronization: the vector is thread-safe, that is, synchronous, And the arraylist is a line.ProgramNot secure, not synchronous
2. Data growth: When we need to increase, the vector grows to the original training by default, while the arraylist is half of the original growth.
Hashmap and hashtable are mainly used in three aspects.
I. Historical Reasons: hashtable is based on the obsolete dictionary class, And hashmap is an implementation of the map interface introduced by Java 1.2.
2. Synchronization: hashtable is thread-safe, that is, synchronous, while hashmap is not secure or synchronous.
3. Value: Only hashmap allows you to use a null value as the key or value of a table entry.
3. Can a Chinese character be stored in a char variable? Why?
A: It can be defined as a Chinese character. Because Java uses unicode encoding and a char occupies 16 bytes, it is okay to put a Chinese character.
4. What are several implementation methods for multithreading? What are the implementation methods of synchronization?
A: multithreading can be implemented in two ways: Inheriting the Thread class and implementing the runnable interface.
There are two types of synchronization implementation: synchronized, wait, and Y.
5. The sequence of class execution during inheritance is generally multiple-choice questions. What will you print out?
A: parent class:
Package test;
Public class fatherclass
{
Public fatherclass ()
{
System. Out. println ("fatherclass create ");
}
}
Subclass:
Package test;
Import test. fatherclass;
Public class childclass extends fatherclass
{
Public childclass ()
{
System. Out. println ("childclass create ");
}
Public static void main (string [] ARGs)
{
Fatherclass fc = new fatherclass ();
Childclass cc = new childclass ();
}
}
Output result:
C: \> JAVA test. childclass
Fatherclass create
Fatherclass create
Childclass create