Typical Java interview questions

Source: Internet
Author: User
Class fuck {static {system. out. println ("this is static");} public fuck () {system. out. println ("this is gozao");} public void S () {system. out. println ("this is parent") ;}} public class test08 extends fuck {public static void main (string [] ARGs) {fuck d = new fuck (); D. S (); Fuck SV = new test08 (); Sv. S ();} public void S () {system. out. println ("this is Son ");}}

The above is a typical interview instance, also as a JavaProgramYou must have a basic understanding of the instance. My summary of the above example is as follows:

1. Whoever calls New: when using the new keyword to create an instance of the class, the method used to call this instance must be the method used to call this class. If this method is not available in this class, calling the parent class method is an inevitable choice.

2. initialize the parent class before initializing the subclass. When you use the new keyword to create a specific instance of a class, you usually need to initialize the class first. However, if the class has a parent class, you must initialize the parent class first. The so-called Initialization is to call the constructor.

3. the initialization class has the following sequence: (1) variable (2) staticCodeBlock (3) Call constructor Initialization

The results can be imagined as follows:

This is staticthis is gozaothis is parentthis is gozaothis is Son

 

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.