Java Video Tutorial 15

Java Video Tutorial 15In this part of the Java Video Tutorial I cover interfaces, abstract classes, abstract methods and more.

You need interfaces and abstract classes because Java doesn’t allow you to inherit from more than one other class. You would use an interface when you want to force the user of the interface to create every method in the interface.

You use an abstract method when you need some flexibility. You’ll learn more in the video below.

If you like videos like this share it [nttfblike]

Code from the Video

DRIVABLE.JAVA

CRASHABLE.JAVA

VEHICLE.JAVA

LESSONFIFTEEN.JAVA

31 thoughts on “Java Video Tutorial 15”

  1. Derek, thanks again for this video, i am just curious how u completed ur Computer programming, i mean are u a self taught programmer if so how much time it took u to reach the level ur now, i know it is kind of personal question, but do answer plz thank you.

    1. I’m mainly book taught, but since I started in the 80s that was the only option. I think anyone can get very good in this day if they focus on object oriented design and uml. Then they can easily learn any oop language like java and c++.

      Feel free to ask questions

  2. You are a great teacher and inspiration. I wish some day I would be like you, sharing knowledge to world free of cost

  3. I am trying to get this to work with the interface and I get this error. What am I doing wrong?

    Exception in thread “main” java.lang.Error: Unresolved compilation problem:
    The type Drivable cannot be a superinterface of Vehicle; a superinterface must be an interface

    at Vehicle.(Vehicle.java:2)
    at LessonFifteen.main(LessonFifteen.java:6)

  4. Hello,
    The topic of interfaces really seems to bog me down, I can’t seem to get my head to click around it. To me, it seems like you are implementing the interface, which defines certain methods which must be used in your class. But, you are also defining them in the class which implements them. Why write the same code twice? Is it simply to make sure that a sort of ‘checklist’ is fulfilled or am I looking at this from the wrong angle?

    Thanks for great videos

  5. thanks a million for your tutorials and code!!!
    Can you recommend or say which book you read and think they are good enough?
    thanks

  6. Hey what is the difference between using the interface and the abstract class I am not sure, seems like you can use either or. Can you give me an example in which you’d use one over the other sorry to be a bother.

    1. With an interface every method must be abstract meaning it can’t do anything at all except force the class that implements it to create that method.

      An abstract class can have non-abstract methods in it that contain code. That is the main difference. Over time you’ll find you rarely use abstract classes, but they are useful when you need them.

  7. Hi Derek, I really didn’t understand what you did with Cat tempCat = (Cat) randAnimal; is this a new class? could you please share a link where it is explained thoroughly?

  8. Hi Derek,
    The best explanation of interfaces I have seen anywhere. You have made many of these concepts that are often explained in very confusing ways, very easy to understand.

  9. Hello Derek. Thanks for the tutorials. I am learning a lot. 🙂

    I want to ask you if we can put two vehicles classes inside the lessonfifteen.java class

    For example can i create another class-> Vehicle carTwo = new Vehicle(5, 200.0); inside the class and print out the output respectively?

    Thanks

Leave a Reply

Your email address will not be published. Required fields are marked *