Static code blocks, class inheritance, and interfaces

Source: Internet
Author: User

1. Text describes the role of static code blocks.

2. What is the order in which the code blocks and constructors are called? is the declaration position of the method relevant? Why? What is the purpose of building blocks of code?

3. Will the static code block be executed when the class loads? How do I manually control class loading?

4. Define the class Person,man,woman to form an inheritance relationship.

5. What is an abstract method? What is an abstract class? Do abstract classes have constructors and can they be overloaded?

6. What are the illegal combinations of abstract modifiers? and give a reasonable explanation?

7.super and this role as well as usage and precautions?

8. Defining the interface

1.IWhite

2.IRich

3.IBeanti

4. Define the class to implement the above three interfaces. (Womenstar)

5. Define the Local Tyrants class (Earchricher.marring (...))

----------------------------------------------------------------------------------------------------

    1. A code block is one of the constituent components of a class, and member variables, member functions, inner classes, and parallel components together. Static code blocks are executed only once when the class is loaded.

    2. Constructing a block of code is called before the constructor, regardless of the location of the declaration, relative to the constructor function. The purpose of building blocks of code: 1, to promote the reuse of code, you can say each constructor of the same code extracted. 2 Initializing objects

    3. Static code blocks are not necessarily executed when the class is loaded. The default way is to execute. If you are invoking a class object as a Java reflection mechanism, you can manually choose to load or not load. Class.forName ("Class name", whether Boolean is loaded);

    4. Class Person
      {
      }
      Class Mans extends Person
      {
      }


      Class woman extends person
      {
      }

    5. There is no method body for abstract methods. Abstract classes refer to classes that have abstract methods. The Java tutorial says that abstract classes have constructors that can be overloaded

    6. Private abstract is illegal and cannot be overridden if it cannot be inherited.

      Abstract final is illegal, final cannot be modified, cannot be modified and cannot be overridden by inheritors

      Abstract static is illegal, static is statically at the time when the class is loaded, it is convenient to access directly with the class, abstract no meaning, access is invalid

    7. Super is a pointer to a superclass object, this is a pointer to this object. Super () The default appears in the first row of all object constructors to represent the creation of superclass objects. Super (..) And this (..) Can only be used in the first row of the constructor, and only two is selected.


    8. Interface Iwhite
      {
      }
      Interface Irich
      {
      }
      Interface Ibueaty
      {
      }

      Interface Iall extends Iwhite,irich,ibueaty
      {
      }

    9. public class Womanstar implements iall{

      }

    10. Class earnricher{

      public void Marry (Iall woman) {

      }

      }

      public static void Main (string[] args) {

      Womanstar star=new Womanstar ()

      New Earnricher (). Marry (Star)

      }

Static code blocks, class inheritance, and interfaces

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.