JAVA basics ---- continuous updates, java basics ----

Source: Internet
Author: User
Tags float double

JAVA basics ---- continuous updates, java basics ----
1. basic Data Type-integer: byte short int long, which is converted to the floating point type when int is used by default. float double is double-boolean by default. the reference types include arrays and classes. The interface type references object = new Constructor (), Person p = new Person (), and Person as a reference type. 3. function or method-method overload: The function name is the same, the number and type of parameters are different, and the return value can be the same or different-Differences between heavy load and rewritingOverride is a class that inherits the function name, parameter type, and the same number occurs in the parent class and subclass relationship. The subclass defines the same method as the parent class, when a subclass is called, you can directly call the method override by the subclass. You do not need to inherit the same function name, parameter type, number, and order in different classes. 4. object-Oriented Design of the Terminal System of the ATM machine: the ATM machine; the bank card money class is the abstract creation of the object is the specific data transmission time: the Data Object transmitted between objects is the access permission of a specific instance of the class -- four private: default in this class: protecte in this package: public in this package and sub-categories of outsourcing: ① encapsulation of the entire project combines the attributes and behaviors of objects into an independent system unit-encapsulation. jar package cmd command: javac executes the java file to generate it. class file javac-d execution. java files and. the class file is compressed. after the jar file is decompressed, modify the files in the met folder, and modify the package name and type, and re-compress them. Otherwise, the program cannot perform ② inheritance (generalization) extends parent class: superclass, base class subclass: derived class super (): Call the parent class constructor this (): Call the class constructor ③ polymorphism must be based on inheritance, without inheritance, there is no polymorphism. When the parent class acts as a method parameter, all subclasses can pass

The reference of the parent class points to the subclass object.

Fruit f = new Apple (); // Fruit acts as the parent class, pointing to the subclass Apple

 

The constructor completes object creation (instantiation) and object initialization.
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 ;}}

 

  ConstructorCreate an object to assign an initial value to the property. By default, a construction method without parameters is defined. However, once a construction method with parameters is defined, the execution sequence of the default construction method without parameters about the parent class subclass is not generated.

 

Variable-local variable: defined in the method body, or the method's form parameter-instance variable: class attribute, global variable-static variable: declared as static attribute memory class
Penson p = new Person ("aa", "11", "male"); // The Object Name p is stored in the stack memory, and the attribute value is stored in the heap memory, p is also called an object reference.

 

Stack memory
-Local variables of the basic data type, object reference value heap memory-Object Attributes. If the elements of the array are New, heap memory is used in other classes or methods, to access the method or attribute of an object, you must instantiate this class and then use the Object Name and vertex operator. In this class, you can directly access the garbage collection mechanism: Acting on the heap memory super () call the constructor of the parent class. static class variables (static variables) are shared by all classes. They are created only when the class is loaded and can be directly called once executed, if a static variable exists in the class, local variables cannot be modified by static. The non-static attributes of instance variables must be called by objects.
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. Therefore, you can create a Test object first and then call the add function.

 

Data type conversion to upward Transformation: subclass conversion to parent class, with inheritance and implementation relationships, loss of new extended attributes of subclass, method downward Transformation: forced conversion
Animal a = new Cat (); // converts Cat c = (Cat) a upward; // converts downward

The instanceof operator is used to determine which subclass is used after the transition

Object instanceof class // determines whether an object belongs to a class object instanceof interface // determines whether an object belongs to an interface // The returned value is boolean.

 

FinalCan 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 classClass defined with abstract

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.