CSC1109_Tutorials/Practice/School/HumanMainClass.java

66 lines
2.0 KiB
Java

package Practice.School;
import Practice.School.Developers.BackendDeveloper;
public class HumanMainClass {
public static void main(String[] args){
//Polymorphism
human h1 = new student("John", 20, "UoG", 5.00);
System.out.print("H1 starts here: ");
h1.sayHello(); //From Student
System.out.println();
((student) h1).doWork(); //I am doing work
((student)h1).getGPA(); // Cast to student to access GPA
BackendDeveloper b1 = new BackendDeveloper("John", 20, "UoG", "Mac", "Java");
human h2 = new BackendDeveloper("John", 20, "Dev", "Mac", "Java");
System.out.println("\nH2 starts here");
// Casting to access methods
((BackendDeveloper)(h2)).code(); //Overriding From abstract class Developer
((BackendDeveloper)(h2)).code("Java"); //Overloading
((BackendDeveloper)(h2)).debug();
((BackendDeveloper)(h2)).doWork("Project");
((BackendDeveloper)(h2)).rest();
h2.sayHello(); //Using polymorphism
// polymorphism
System.out.println("\nB1 starts here");
b1.code();
b1.debug();
b1.doWork("Project");
b1.rest();
//BackendDeveloper b = new BackendDeveloper("John", 20, "UoG", "Mac", "Java");
BackendDeveloper b = new BackendDeveloper();
b.doWork("game");
Dataset DA = new Dataset();
int [] x = DA.getId();
for(int i = 0; i < x.length; i++){
System.out.println(x[i]);
}
//Output:
// H1 starts here: From Student
// I am doing work
// My GPA is 5.0
//
// H2 starts here
// My name is John and I am coding in Java
// I am coding in Java
// I am debugging in Java
// I am doing Project on my Mac
// I am on a break
// Hello, my name is John and I am 20 years old.
//
// B1 starts here
// My name is John and I am coding in Java
// I am debugging in Java
// I am doing Project on my Mac
// I am on a break
}
}