Basic application of Java reference delivery

Source: Internet
Author: User
Tags fun call java reference

Package com.cloud.day1;


public class Demo1 {
public static void Main (string[] args) {
//reference delivery for basic applications
Demo2 d2=new Demo2 ();
d2.temp=500;
System.out.println ("Fun call Before:" +d2.temp);
Fun (D2);
System.out.println ("Fun call After:" +d2.temp);
System.out.println ("**********");
String str1= "Hello";
System.out.println ("Fun1 before Call:" +STR1);
FUN1 (STR1);
System.out.println ("Fun1 after Call:" +STR1);
System.out.println ("**********");
Demo3 d3=new Demo3 ();
D3.temp= "World";
System.out.println ("Fun1 before Call:" +d3.temp);
FUN2 (D3);
System.out.println ("Fun1 after Call:" +d3.temp);
//Receive your own reference to this class
System.out.println ("**********");
Demo4 d4=new Demo4 ();
D4.settemp (100);
D4.fun (D4);
System.out.println (D4.gettemp ());
//Case: One by one correspondence
Person Per=new person ("Tom", 20);
Book Bk=new book ("Java Tutorial", 50.0f);
Per.setbook (BK);
Bk.setperson (per);
System.out.println ("People looking for books:" +per.getname () + "--" +per.getbook (). GetTitle () + "--" +per.getbook (). GetPrice ());
System.out.println ("Book Someone:" +bk.gettitle () + "--" +bk.getperson (). GetName ());
}
public static void Fun (Demo2 D2) {
d2.temp=1000;
}
public static void Fun1 (String str2) {
Str2= "MDLD";
}
public static void Fun2 (Demo3 D3) {
d3.temp= "MLDL";
}
}
Class demo2{
int temp=100;
}
Class demo3{
String temp= "Hello";
}
Class demo4{
private int temp=30;
public void Fun (Demo4 d4) {
d4.temp=40;
}
public int gettemp () {
return temp;
}
public void settemp (int temp) {
This.temp = temp;
}
}
Class person{
private String name;
private int age;
Private book book;
Public String GetName () {
return name;
}
public void SetName (String name) {
THIS.name = name;
}
public int getage () {
return age;
}
public void Setage (int.) {
This.age = age;
}
Public book GetBook () {
return book;
}
public void Setbook (book book) {
This.book = Book;
}
Public person (String Name,int age) {
This.setname (name);
This.setage (age);
}
}
Class book{
Private String title;
private float price;
private person person;
Public book (String title,float Price) {
This.settitle (title);
This.setprice (price);
}
Public String GetTitle () {
return title;
}
public void Settitle (String title) {
This.title = title;
}
public float GetPrice () {
return price;
}
public void Setprice (float price) {
This.price = Price;
}
Public Person Getperson () {
return person;
}
public void Setperson (person person) {
This.person = person;
}

}

The last case is important and is applied to the three javaweb frameworks.

Copyright Notice: Bo Master original articles, reproduced please indicate the source. Http://blog.csdn.net/dzy21

Basic application of Java reference delivery

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.