fork download
  1.  
  2.  
  3. import java.util.*;
  4. import java.lang.*;
  5. import java.io.*;
  6.  
  7. class Author{
  8. String authorName;
  9. int age;
  10. String place;
  11. Author(String name,int age,String place){
  12. this.authorName=name;
  13. this.age=age;
  14. this.place=place;
  15. }
  16. public String getAuthorName(){
  17. return authorName;
  18. }
  19. public int getAge(){
  20. return age;
  21. }
  22. public String getPlace(){
  23. return place;
  24. }
  25. }
  26.  
  27. class Book{
  28. String name;
  29. int price;
  30. Author auth;
  31. Book(String n,int p,Author at){
  32. this.name=n;
  33. this.price=p;
  34. this.auth=at;
  35. }
  36. public void showDetail(){
  37. System.out.println("Book is"+name);
  38. System.out.println("price "+price);
  39. System.out.println("Author is "+auth.getAuthorName());
  40. }
  41. }
  42.  
  43. class Test{
  44. public static void main(String args[]){
  45. Author ath=new Author("Me",22,"India");
  46. Book b=new Book("Java",550,ath);
  47. b.showDetail();
  48. }
  49. }
Success #stdin #stdout 0.04s 4386816KB
stdin
Standard input is empty
stdout
Book isJava
price 550
Author is Me