• Source
    1. /* package whatever; // don't place package name! */
    2.  
    3. import java.util.*;
    4. import java.lang.*;
    5. import java.io.*;
    6.  
    7. /* Name of the class has to be "Main" only if the class is public. */
    8. class Ideone
    9. {
    10. public static void main (String[] args) throws java.lang.Exception
    11. {
    12.  
    13. Vector<Student> sampleData =new Vector<Student>();
    14. Student s= new Student("ashis", "a@ya.com");
    15. sampleData.add(s);
    16. s= new Student("rahim", "r@ya.com");
    17. sampleData.add(s);
    18.  
    19. System.out.println("Value is :"+sampleData.get(1));
    20. Teacher teacher = new Teacher("Tapan","tap@gmail.com");
    21. Course sample= new Course(sampleData, teacher, "Physics");
    22. s= new Student("Jiban", "j@ya.com");
    23. sample.addStudent(s);
    24.  
    25. System.out.println( sample.getTitle());
    26. s= sample.getStudent();
    27. System.out.println("Name: "+ s.getName()+ " Email: "+ s.getEmail());
    28.  
    29.  
    30. }
    31. }
    32.  
    33.  
    34. abstract class Member {
    35. private String name;
    36. private String email;
    37. public Member(String name, String email){
    38. this.name= name;
    39. this.email= email;
    40.  
    41. }
    42. public String getName(){
    43. return name;
    44. }
    45. public String getEmail(){
    46. return email;
    47. }
    48.  
    49. }
    50.  
    51. // *******************************************
    52. class Student extends Member {
    53. public Student(String name, String email){
    54. super(name, email);
    55. }
    56. public String toString()
    57. {
    58. return "st";
    59. }
    60. }
    61.  
    62. class Teacher extends Member{
    63. public Teacher(String name, String email){
    64. super(name, email);
    65. }
    66.  
    67. }
    68. // *******************************************
    69.  
    70. class Course {
    71. private Vector<Student> myVector;
    72. private Teacher lecturer;
    73. private String title;
    74. public Course( Vector<Student> myVector, Teacher lecturer,String title){
    75. this.myVector= myVector;
    76. this.lecturer= lecturer;
    77. this.title= title;
    78. }
    79. public void addStudent(Student st){
    80. myVector.add(st);
    81.  
    82. }
    83. public void removeStudent(int index){
    84. myVector.remove(index);
    85. }
    86.  
    87. public Student getStudent(){
    88. Student s;
    89. s= myVector.get(0);
    90. return s;
    91. }
    92. public String getTitle(){
    93. return title;
    94. }
    95. public void assignTeacher(Teacher lec){
    96. lecturer= lec;
    97. }
    98.  
    99.  
    100. }
    101.  
    102.  
    103.