对象一对一关系
来源:互联网 发布:中国为什么网络扫黄 编辑:程序博客网 时间:2024/05/22 14:23
package class1;
class Person {
private String name ;
private int age ;
private Book book ;
public Person(String name , int age){
this.setName(name) ;
this.setAge(age) ;
}
public void setName(String name) {
this.name = name ;
}
public void setAge(int age) {
this.age = age ;
}
public String getName() {
return this.name ;
}
public int getAge() {
return this.age ;
}
public void setBook(Book book) {
this.book = book;
}
public Book getBook() {
return book ;
}
}
class Book {
private String title ;
private float price ;
private Person person ;
public Book(String title,float price) {
this.setTitle(title) ;
this.setPrice(price) ;
}
public void setTitle(String title) {
this.title = title ;
}
public String getTitle(){
return this.title ;
}
public void setPrice(float price) {
this.price = price ;
}
public float getPrice() {
return this.price ;
}
public void setPerson(Person person) {
this.person = person ;
}
public Person getPerson() {
return this.person ;
}
}
public class RefDemo05 {
public static void main(String args[]) {
Person p = new Person("张三",30) ;
Book b = new Book("java",90.0f) ;
p.setBook(b) ;
b.setPerson(p);
System.out.println("从人找到书-->姓名:" + p.getName() + "; 年龄:" + p.getAge() + "; 书名:" + p.getBook().getTitle()
+ "; 价格:" + p.getBook().getPrice());
System.out.println("从书找到人-->书名:" + b.getTitle() + "; 价格:" + b.getPrice() + "; 姓名:" + b.getPerson().getName()
+ "; 年龄:" + b.getPerson().getAge());
}
}
class Person {
private String name ;
private int age ;
private Book book ;
public Person(String name , int age){
this.setName(name) ;
this.setAge(age) ;
}
public void setName(String name) {
this.name = name ;
}
public void setAge(int age) {
this.age = age ;
}
public String getName() {
return this.name ;
}
public int getAge() {
return this.age ;
}
public void setBook(Book book) {
this.book = book;
}
public Book getBook() {
return book ;
}
}
class Book {
private String title ;
private float price ;
private Person person ;
public Book(String title,float price) {
this.setTitle(title) ;
this.setPrice(price) ;
}
public void setTitle(String title) {
this.title = title ;
}
public String getTitle(){
return this.title ;
}
public void setPrice(float price) {
this.price = price ;
}
public float getPrice() {
return this.price ;
}
public void setPerson(Person person) {
this.person = person ;
}
public Person getPerson() {
return this.person ;
}
}
public class RefDemo05 {
public static void main(String args[]) {
Person p = new Person("张三",30) ;
Book b = new Book("java",90.0f) ;
p.setBook(b) ;
b.setPerson(p);
System.out.println("从人找到书-->姓名:" + p.getName() + "; 年龄:" + p.getAge() + "; 书名:" + p.getBook().getTitle()
+ "; 价格:" + p.getBook().getPrice());
System.out.println("从书找到人-->书名:" + b.getTitle() + "; 价格:" + b.getPrice() + "; 姓名:" + b.getPerson().getName()
+ "; 年龄:" + b.getPerson().getAge());
}
}
阅读全文
0 0
- 对象的一对一关系
- 对象的一对一关系
- 对象一对一关系
- Hibernate一对一关系操作对象
- Hibernate对象关系映射---一对一
- Hibernate对象关系映射---一对一
- hibernate对象关系映射(一对一,…
- JAVA_对象一对一关系 ObjectOneToOneRelationship.java
- JAVA面向对象(基础篇)之一对一关系
- Hibernate入门BLOG[七、Hibernate对象关系一对一映射]
- Hibernate之对象关系映射01一对一单向关联
- Hibernate之对象关系映射02一对一单向主键关联
- Hibernate之对象关系映射04一对一双向关联
- Hibernate之对象关系映射05一对一双向主键关联
- Hibernate之对象关系映射07一对一多单向关联
- Java复习——对象的一对一关系
- Hibernate的一对一关系
- Hibernate中的一对一关系
- Redux 入门教程(一):基本用法
- Python学习笔记
- 学习笔记1——数字基带信号编码
- Android Studio jar包引用jar包
- 二维数组中的查找
- 对象一对一关系
- Dubbo 使用注解替换XML控指针异常
- 79. Word Search
- 构建装备制造服务业的项目绩效管理体系
- MTK的lcm背光流程和客制化
- Hibernate xml配置
- Yii的表单提交
- 关于NoSql数据库的看法
- telnet通过smtp发送邮件