Big Data Fifth day job

Source: Internet
Author: User
Tags define local

1. Describe the function of static code blocks

A: The static code block executes only once when the class is loaded, and can be used to initialize the resource file, especially if the resource file is only loaded once

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?

A: Constructing code blocks is performed before the constructor, regardless of the declaration position of the method. Construct code blocks to implement code reuse or to initialize property member variables

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

A: Class loading does not necessarily load static code blocks, and when you load a class with forname, you can control it by setting its second parameter.

public class Main {

public static void Main (string[] args) throws Exception {

Class.forName ("homework. Person ", False,person.class.getclassloader ()). GetName ();

}

}

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

For:

Class person{}

Class Man extends person{}

Class Woman extends person{}

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

A: Abstract methods are subclass-public methods, defined in the parent class, inherited and implemented by subclasses, and abstract methods can only be defined in abstract classes and cannot have a method body. Abstract methods have constructors

, it is called when the subclass is instantiated, and the method can be overloaded.

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

For:

A.abstract+static:static indicates that the method belongs to a class only, but the abstract method defined in the abstract class has no method body, even if it does not make any sense.

B.abstract+private: The private method of the parent class cannot be implemented after the subclass inherits its permissions to become inaccessible.

C.abstract+final:fianal indicates that the method cannot be overridden, which violates the core idea of an abstract method, that is, subclasses inherit and rewrite.

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

A: Super is a reference to the superclass of the current class, and super () calls the constructor of the parent class of the current class.

This is a reference to the current class, and this () invokes the constructor method of the current class.

These two methods can only be written in the first line of the method body when used.

8. Bai Fu Mei case

For:

Define three interfaces:

public Interface iwhite{}

public Interface irich{}

public Interface ibeauty{}

The definition class implements the above interface:

public class Supergirl implements iwhite,irich,ibeauty{}

Define Local tyrants:

public class hao{

public void marring (Supergirl) {

System.out.println ("Local tyrants only accepts mating" +new Supergirl ())

}

}


Big Data Fifth day job

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.