How to configure the Java EE Development environment in the Linux environment with Eclipse + Tomcat + MySQL

Source: Internet
Author: User
Tags modifier modifiers

It summarizes the three main features of object-oriented in Java, and now talk about the abstract class, interface, inner class and other features in Java.

I. Abstract class
Public abstract class Shape {public        int shapeid = 0;public abstract double Getarea ();}
    1. Java allows classes, interfaces, or member methods to have abstract properties, without allowing member fields or constructor methods to have abstract properties.
    2. Class modifiers contain abstract properties, called abstract classes, and interfaces always have abstract properties.
    3. If the modifier of a member method contains abstract, the member method has an abstract property, called an abstract method. An abstract method can only be defined in an abstract class or interface. Abstract classes generally have at least one abstract method, so generally speaking, the class containing the abstract method is called abstract class.
    4. Abstract methods do not contain method bodies, in the following format:
      [Method modifier Word list] Returns the type method name (parameter list);
    5. An abstract class can have a construction method, but cannot generate an instance directly, and an instance must be generated from a non-abstract subclass.
    6. If the subclass of an abstract class is not an abstract class, then it is required that all abstract methods of the parent class (abstract class) must be overwritten in the definition of the child class.
Two. Interface Java does not allow a subclass to have multiple direct parent classes, but allows a class to implement multiple interfaces. The format of the interface definition is:[interface modifier word list] Interface interface name [extends interface list] {interface body}
Public interface Shape {public static final double PI = 3.14159;public abstract double Getarea ();}
    1. external interfaces, like external classes, generally do not have protected and private properties
    2. The interface itself has an abstract property, so an abstract modifier is unnecessary.
    3. There is no construction method inside the interface body, the instance object cannot be generated directly through the interface
    4. All member fields of an interface have public, static, and final properties; All member methods of an interface have public and abstract properties
    5. If the class that implements the interface is not an abstract class, you need to define all the member methods in that interface to be overridden in the class body of the class.
Three. Inner class real name inner class
    1. The encapsulation modifiers of the real-name inner class add protected and private. Can be selected according to the situation.
    2. For a real-name inner class that does not have a static property, it must have a final property if its member field has a static property, and a real-name inner class that does not have a static property cannot contain a method with a static property.
    3. How to create a real-name inner class instance object
      * Instance object of static real name inner class:
      New external class name. real name internal class names (parameter list)
      *
      instance objects for real-name inner classes that do not have static properties:
      Outer class expression. New real name internal class names (parameter list)
Anonymous inner class anonymous inner class does not have a class name, cannot have abstract and static properties, and cannot derive a subclass. The definition format for anonymous inner classes is:new Parent type name (argument list) {class Body}
An example is easier to understand:
Abstract class ClassA {int data;public ClassA (int i) {data = i;} public abstract void Method (); public class ClassB {public static void main (string[] args) {ClassA a = new ClassA (3) {public void method () {SYSTEM.OUT.PR INTLN (data);}}; A.method ();}}
Four. Final modifier
    1. A class with a final attribute cannot derive subclasses
    2. If the member field has a final attribute, it cannot be changed after the assignment. If a member field has both final and static properties, it can only be assigned when defined, and if the member field has only a final property and does not have a static property, it can be assigned only at the time of definition or in the constructor method.
    3. If a member method of a class has a final property, it cannot be overridden by a member method of the subclass of the current class.
Five. Static modifiers in addition to inner classes, classes generally do not have static properties. The reasons and characteristics of static internal classes need to be further studied.
Six. Miscabstract, static, Final is the three commonly used modifiers. Only static and final two modifiers can be combined in these three modifiers.
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.