The concept of reference type in Java and the difference between string two instantiation methods

Source: Internet
Author: User
The reference type (reference type) points to an object, not the original value, and the variable that points to the object is a reference variable.

The other types of the basic data types in Java are reference data types, and class classes that you define are reference types that can be used as basic types.

Examples are as follows:

public class MyDate {
private int day = 8;
private int month = 8;
private int year = 2008;
Private mydate (int day, int month, int year) {...}
public void print () {...}
}
public class Testmydate {
public static void Main (String args[]) {
This today variable is a variable of a reference type
MyDate today = new MyDate (23, 7, 2008);
}
}

2. Assignment of reference type

In the Java programming language, a variable declared with a type of a class is specified as a reference type because it is referencing a non original type, which is important for assigning values. The following code:

int x = 7;
int y = x;
String s = "Hello";
String T = s;

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.