Last active
May 2, 2021 08:13
-
-
Save canyoldas0/b6c0d3fd974d94d6f4001589e627b9f9 to your computer and use it in GitHub Desktop.
Inheritance practice
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package com.company; | |
public class Instructor extends User{ | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package com.company; | |
public class InstructorManager extends UserManager{ | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package com.company; | |
public class Main { | |
public static void main(String[] args) { | |
StudentManager studentManager = new StudentManager(); | |
InstructorManager instructorManager= new InstructorManager(); | |
UserManager userManager= new UserManager(); | |
Student student1= new Student(); | |
student1.setId(1); | |
student1.setFirstName("Can"); | |
student1.setLastName("Yoldaş"); | |
student1.setEmail("can.yoldas0@outlook.com"); | |
Instructor instructor1= new Instructor(); | |
instructor1.setId(2); | |
instructor1.setFirstName("Engin"); | |
instructor1.setLastName("Demiroğ"); | |
instructor1.setEmail("engindemirog@gmail.com"); | |
userManager.add(student1); | |
userManager.add(instructor1); | |
userManager.signIn(student1); | |
studentManager.registerToClass(student1); | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package com.company; | |
public class Student extends User{ | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package com.company; | |
public class StudentManager extends UserManager{ | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package com.company; | |
public class User { | |
private int id; | |
private String firstName; | |
private String lastName; | |
private String email; | |
public int getId() { | |
return id; | |
} | |
public void setId(int id) { | |
this.id = id; | |
} | |
public String getFirstName() { | |
return firstName; | |
} | |
public void setFirstName(String firstName) { | |
this.firstName = firstName; | |
} | |
public String getLastName() { | |
return lastName; | |
} | |
public void setLastName(String lastName) { | |
this.lastName = lastName; | |
} | |
public String getEmail() { | |
return email; | |
} | |
public void setEmail(String email) { | |
this.email = email; | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package com.company; | |
public class UserManager { | |
public void add(User user) { | |
System.out.println("New user is added: " +user.getFirstName() + " " + user.getLastName()); | |
} | |
public void signIn(User user) { | |
System.out.println("Signed in."); | |
} | |
public void signOut(User user) { | |
System.out.println("Signed out."); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment