Java Foundation----Continuous update

Source: Internet
Author: User
Tags float double

1. Basic Data Types-Integer type: byte short int long default to int required conversion-float type: Float double defaults to double-Boolean type: boolean-character type2. Reference types include arrays, classes, interfacesType Reference Object = new construction method (); person p = new person (); Person as a reference type3. Functions or methods-Method ofOverload: Function name, parameter number, type is different, return value can be the same- the difference between overloading and overridingOverrides are inherited function names, parameter types, the same number of classes that occur in the parent class and subclass relationships, subclasses define exactly the same method as the parent class, and the subclass calls the method that the subclass overrides directlyoverloads do not have the same name as the inherited function, the type, number, and order of the arguments occur in a class4. Object-orientedDesign the terminal system of ATM machine: ATM machine; bank card Money class is abstract when you create an object that is specific to the data passing time: Considering that the object is passing data between objects is a concrete instance of the classaccess Rights--fourPrivate: The default in this class: Protecte in this package: in this package, in the outsourced subclass public: throughout the project ① Encapsulation combines the properties and behavior of an object within a separate system unit -encapsulation. jar PackageCMD command: Javac Executes the Java file so that it generates a. class file javac-d executes the. java file and the. class file is compressed into a. jar file and requires a re-decompression to modify the files in the Met folder to package name and type Modify all the re-compression or you can't do it. ② Inheritance (generalization) Extends parent class: Superclass, base class subclass: Derived class super (): Call parent class constructor This (): Call this class constructor③ polymorphism Polymorphism must be based on inheritance, without inheritance there is no polymorphism when the parent class is the formal parameter of the method, all subclasses can pass

A reference to the parent class is directed to the child class object

Fruit f = new Apple ();//fruit as the parent class, point to child class Apple

ConstructorsCompletion of object creation (instantiation) generally also completes initialization of objects
public class person{     String name;     int age;     String sex;     Constructor public person     (String name, int age,string s) {          this.name=name;          This.age=age;          This.sex=sex;}     }

Construction MethodCreate object assign an initial value to a property default one parameterless constructor but once the constructor method with parameters is defined, no default parameterless construction method is generatedabout the execution order of the parent class subclass

variables-Local variables: defined in a method body, or a method's parameter-instance variable: A property of a class, a global variable-Static variables: properties declared as staticcategory of Memory
Penson p = new person ("AA", "one", "male");//object name p is stored in stack memory,  property value exists in heap memory, p is also referred to as object reference

Stack Memory
-Local variables of the base data type, reference values of the objectHeap Memory-Object properties, array of elements with new on heap memoryIn other classes or methods, to access the methods or properties of an object, you must instantiate the class, and then complete it by using the object name and the dot operator, which is accessed directly in this class.garbage Collection mechanism: Acting on heap memorySuper () Call the constructor method of the parent classThe static class variable (static variable) is shared by all classes, created only when the class is loaded, executed once and can be called directly, the existence of a static variable exists in the classLocal variables are not allowed to be modified by staticinstance variable non-static propertyA non-static method must be called with an object
public class test{public     void Add (int. A,int b) {} public     static void main (String []args) {          Test t = new test;
   t.add;     }} Add is a non-static method, the main method is static, so you can create the test object first, then call the Add function

Conversion of data typesTransition up: Subclass converted to parent class with inheritance and implementation relationships, loss of new extended properties of subclasses, method downward transformation: Cast
Animal a = new Cat ();//Up conversion cat C = (cat) a;//down conversion

The instanceof operator determines which subclass after the upstream transformation

Object instanceof class//Determines whether an object belongs to a class object instanceof interface//determines whether an object belongs to an interface//The return value is a Boolean

final can be modified:-Class: Cannot be inherited-variable: equivalent to constant-method: InterfaceOnly constants and abstract method constants in: public static final abstract method: Public abstract abstract class Classes defined with an abstract

Java Foundation----Continuous update

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.