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