A large collection of Java classic questions

Source: Internet
Author: User
Tags inheritance interface thread thread class
Set | Problem 1, scope public,private,protected, and the difference when not written
Answer: The difference is as follows:
Scope Current class same package descendant class other package
Public√√√√
Protected√√√x
Friendly√√xx
Private√xxx
Default to friendly when not written

2, the difference between ArrayList and Vector, HashMap and Hashtable
A: ArrayList and Vector are mainly from two aspects.
I. Synchronicity: vectors are thread-safe, that is, synchronous, while ArrayList is not secure, not synchronized.
Two. Data growth: When growth is needed, the vector defaults to the original one, while ArrayList is half the original.
On HashMap and Hashtable mainly from three aspects.
I. Historical reasons: Hashtable is based on the old dictionary class, HashMap is an implementation of the map interface introduced by Java 1.2
Two. Synchronicity: Hashtable is thread-safe, that is, synchronous, and HashMap is not secure, not synchronized.
Three. Value: Only HashMap can let you use NULL as the key or value of a table entry

3, char variable can be stored in a Chinese character?
A: can be defined as a Chinese, because Java in Unicode encoding, a char for 16 bytes, so put a Chinese is no problem

4, multithreading there are several ways to achieve, what is it? There are several ways to achieve synchronization.
A: Multithreading has two implementation methods, is the inheritance of the thread class and implementation of the Runnable interface
There are two kinds of implementations of synchronization, namely Synchronized,wait and notify

5, the Inheritance time class execution order question, is generally the choice question, asks you to be able to print what?
Answer: The parent class:
Package test;
public class Fatherclass
{
Public Fatherclass ()
{
System.out.println ("Fatherclass Create");
}
}
Sub class:
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 results:
C:\>java test. ChildClass
Fatherclass Create
Fatherclass Create
ChildClass Create


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.