Java EE Basics (10)

Source: Internet
Author: User
Tags modifiers

1. Object-oriented (overview and role of the package keyword)
    • A: Why should I have a bag
      • Classify byte code (. Class)
      • The package is actually a folder
    • B: Overview of the Package
    • Example: Student: Add, delete, modify, query teacher: Add, delete, modify, inquire ...

      方案1:按照功能分    com.heima.add        AddStudent        AddTeacher    com.heima.delete        DeleteStudent        DeleteTeacher    com.heima.update        UpdateStudent        UpdateTeacher    com.heima.find        FindStudent        FindTeacher方案2:按照模块分    com.heima.teacher        AddTeacher        DeleteTeacher        UpdateTeacher        FindTeacher    com.heima.student        AddStudent        DeleteStudent        UpdateStudent        FindStudent
2. Object-oriented (definition of package and matters needing attention)
    • A: Define the format of the package
      • Package name;
      • Multi-stage ladle. Separate
    • B: Considerations for defining packages
      • The A:package statement must be the first executable code of the program
      • The B:package statement can have only one in a Java file
      • C: If there is no package, default means no packages name
    • C: Case Demo
      • Package Definition and Precautions
3. Object-oriented (class compile and run with package)
    • A: How to compile a class that runs a package
      • A:javac when compiling with-D
        • Javac-d.
      • B: Execute via Java command.
        • The Java package name. Hellword
4. Object-oriented (access between classes under different packages)
    • A: Case Demo
      • Access between classes under different packages
5. Object-oriented (overview and use of the Import keyword)
    • A: Case Demo
      • Why should I have an import
        • In fact, the class that has the package is visible to the caller without having to write the full class name.
    • B: Guide Package format
      • Import package name;
      • Attention:
      • This way the import is to the name of the class.
      • Although it can be written last *, but not recommended.
    • C:package,import,class there is no sequential relationship (interview question)
6, Object-oriented (four kinds of permission modifiers test)
    • A: Case Demo
      • Four types of permission modifiers
    • B: Conclusion
    •             本类   同一个包下(子类和无关类)  不同包下(子类)    不同包下(无关类)private     Y       默认          Y       Yprotected   Y       Y                           Ypublic      Y       Y                           Y               Y
7. Object-oriented (common modifiers used by the class and its composition)
    • A: modifier:
      • permission modifier: private, default, protected,public
      • status modifier: static,final
      • abstract modifier: Abstrac T
    • B: class:

      • permission modifier: default modifier, public
      • status modifier: Final
      • Abstract modifier: Abstrac T

      • Uses the most: public

    • C: Member variable:

      • permission modifier: private, default, Protected,pu Blic
      • Status modifier: static,final

      • The most used is: private

    • D: Construction method:

      • Permission modifier: Private, default, Protected,public

      • The most common use of
      • is: public

    • E: Member Method:

      • permission modifier: private, default, protected,public
      • status modifier: static,final
      • Abstract modifier: AB Stract

      • Uses the most: public

    • F: In addition to the combination rule:

      • member variable: public static F Inal
      • member Method:
        • public static 
        • public abstract
        • public final
8. Object-oriented (internal class overview and access Features)
    • A: Internal class overview
    • B: Internal class Access features
      • A: The inner class can access the members of the external class directly, including the private.
      • B: The external class must create an object to access the members of the inner class.
      • The external class name. Internal class Name Object name = External Class object. Inner class object;
    • C: Case Demo
      • Internal class extremely accessible features
9. Object-oriented (private use of member inner Class)
    • Private
10. Object-oriented (static member inner Class)
    • Static
    • B: The member inner class is accessed by statically modifying the following methods:
      • The external class name. Internal class Name Object name = External class name. Inner class object;
11, Object-oriented (members of the internal class of interview questions)
    • A: Face Test
    • 要求:使用已知的变量,在控制台输出30,20,10。class Outer {    public int num = 10;    class Inner {        public int num = 20;        public void show() {            int num = 30;            System.out.println(?);            System.out.println(??);            System.out.println(???);        }    }}class InnerClassTest {    public static void main(String[] args) {        Outer.Inner oi = new Outer().new Inner();;    }   }
12, Object-oriented (local internal class access to local variables of the problem)
    • A: Case Demo

      • Local internal class access local variables must be final decorated
      • Local inner class in accessing the local variables in his method must be final decorated, why? Because when this method is called, if the local variable is not final decorated, his life cycle and method life cycle is the same, when the method of the stack, the local variable will disappear, then if the local inner class object has not disappeared immediately want to use this local variable, there is no, If the final decoration will enter the constant pool when the class loads, even if the method is stacked, the constant pool constant is still there, you can continue to use

        But jdk1.8 canceled this thing, so I think it's a bug.

13. Object-oriented (the format and understanding of anonymous inner classes)
    • A: Anonymous Inner class
      • is the simplified notation of the inner class.
    • B: Premise: There is a class or interface
      • The class here can be either a concrete class or an abstract class.
    • C: Format:
    • new 类名或者接口名(){    重写方法;}
    • D: What is the essence?
      • is an anonymous object that inherits the class or implements the interface's subclass.
    • E: Case Demo
      • An anonymous inner class as required
14. Object-Oriented (anonymous inner class overrides multiple method calls)
    • A: Case Demo
      • Method invocation for Anonymous inner class
15, Object-oriented (anonymous internal class in the development of the application)
    • A: The code is as follows
    • //这里写抽象类,接口都行abstract class Person {    public abstract void show();}class PersonDemo {    public void method(Person p) {;    }}class PersonTest {    public static void main(String[] args) {        //如何调用PersonDemo中的method方法呢?        PersonDemo pd = new PersonDemo ();    }}
16, Object-oriented (anonymous internal class interview questions)
    • A: Face Test
    • 按照要求,补齐代码interface Inter { void show(); }class Outer { //补齐代码 }class OuterDemo {    public static void main(String[] args) {          Outer.method().show();      }}要求在控制台输出”HelloWorld”

Java EE Basics (10)

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: 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.