Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

I am in a Java programming class, and it focuses on Object Oriented Programming

ID: 3759838 • Letter: I

Question

I am in a Java programming class, and it focuses on Object Oriented Programming aspects. I understand them for the most part, but when it comes to the application of it, I start to struggle. I would greatly appreciate it if you could explain to me in detail (maybe examples if you can) how these following terms work in Java (like how they are commonly used) and their purpose. THANK YOU.

* Dynamic type

* Static type

* Dynamic Dispatch

* Abstract Classes/Methods

* How to properly use the super keyword

* How to override/ overload

Explanation / Answer

public class StaticBindingTest {
  
public static void main(String args[]) {
Collection c = new HashSet();
StaticBindingTest et = new StaticBindingTest();
et.sort(c);
  
}

//overloaded method takes Collection argument
public Collection sort(Collection c){
System.out.println("Inside Collection sort method");
return c;
}
  

//another overloaded method which takes HashSet argument which is sub class
public Collection sort(HashSet hs){
System.out.println("Inside HashSet sort method");
return hs;
}
  
}


public class DynamicBindingTest {

public static void main(String args[]) {
Vehicle vehicle = new Car(); //here Type is vehicle but object will be Car
vehicle.start(); //Car's start called because start() is overridden method
}
}

class Vehicle {

public void start() {
System.out.println("Inside start method of Vehicle");
}
}

class Car extends Vehicle {

@Override
public void start() {
System.out.println("Inside start method of Car");
}
}