Java Basic (four) face question

Source: Internet
Author: User

Interview questions:

    • Construct code blocks, construct methods, and prioritize static code?
    • Static code blocks > Constructing code blocks > Construction Methods

Interview question: What is the difference between overload and override?
Overload: Method Overloading
Method names, parameters differ, and return values are not related
Different parameters:
1) different number of parameters
2) different parameter types
Override: Method Override (subclass defines a method declaration that is the same as a parent class)
Continue to use in the

2 about the difference between this and super?
This: Represents the object of the current class
Super: Represents the parent class spatial identity, which is understood as an object representing the parent class

    应用场景:            this:            super:                    成员变量                            this.成员变量                            super.成员变量                    成员方法                            this.成员方法()                            super.成员方法();                    构造方法                            this()/this("..")    面试题:
    • Local internal classes Access local variables, then problems occur? (Jdk7 previously included jdk7, this problematic)
    • Error, need to add final decoration to local variables ...
    • Why does this local variable have to be final decorated?
    • The local variable should also be used in the inner class, change the variable to a fixed value, always exist in memory, and invoke the members of the inner class through the main method.

      Anonymous internal class interview questions:
      According to the requirements, the code
      Interface Inter {void Show ();
      Class Outer {//Padded code}
      Class Outerdemo {
      public static void Main (string[] args) {
      Outer.method (). Show ();
      }
      }
      Required to output "HelloWorld" on the console

    • */
      Interface inter3{
      void Show ();//public abstract
      }
      Class outer7{
      The code is padded
      public static Inter3 method () {

      //返回的是接口:当前并不提供接口的子实现类,所以只能用匿名内部类return new Inter3() {    public void show() {        System.out.println("helloworld");    }};

      }
      }
      Test class
      public class Test {

      public static void Main (string[] args) {

      Outer7.method().show();

      }
      }

Java Basic (four) face question

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.