Java Basics (i)---this,super and integer

Source: Internet
Author: User

The difference between 1.this and super

This and super can only be used in non-static methods, not in static methods, such as Static,final

This: can only be used in a method body, equivalent to a pointer in C, to a member variable, this action in asubclass

Private String password;  Public void First () {    System.out.println ("This cannot appear in a static method");}  Public void second () {      this. First ();        This . Password;}

Super: Invokes the constructor of the parent class, or is used internally by a non-static member of a class. e.g. Super.method ()

Must be written on the first line of the constructor

classFatherclass { Public intvalue;  Public voidf () {value= 100; System.out.println ("Fatherclass value =" +value); }}classChildClassextendsfatherclass{ Public intvalue;  Public voidf () {Super. f (); Value= 200; System.out.println ("Childclass.value=" +value);          System.out.println (value); System.out.println (Super. Value); }}

The difference between int and integer in 2.java

(1). int is the underlying data type, and integer is a complex data type, and integer is a class

The int variable is initially 0,integer NULL when the class is initialized

(2). Initialize

int i = 1; Integer i = new integer (1);

(3). When adding data in ArrayList and HashMap, only integer is used,

and the generic definition does not support int: such as:list<integer> list = new arraylist<integer> (); Yes list<int> list = new arraylist< Int> ();

ArrayList al=New= 1; integer NI=new  integer (n); Al.add (n) ; // can not Al.add (NI); // can be

int is simply used to perform some subtraction operations or to pass as parameters

An integer can be used for object manipulation

(4). Other functions are similar

Float float;double double;string String

Basic data types Packing class
Byte Byte
Boolean Boolean
Short Short
Char Character
Int Integer
Long Long
Float Float
Double Double

(5). int and integer type conversions

The first type is:

//int goes to integerinti = 0; Integer Test=NewInteger (i);//Integer to intInteger Wrapperi =NewInteger (0); inti =Wrapperi.intvalue (); //due to the presence of autoboxing, it can be used directlyinti = 0; Integer Test=i; //valueof can also be type-converted and more efficient, there is a caching mechanism Public StaticInteger ValueOf (inti)inti = 0; Integer Test= Integer.valueof (i);

Java Basics (i)---this,super and integer

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.