Modeling Entities in Java: Methods, Method Overloading, & Constructors
Java
| Intermediate
- 12 videos | 1h 32m 17s
- Includes Assessment
- Earns a Badge
Modeling complex entities involves defining and invoking methods and constructors. Furthermore, defining robust and reusable code requires learning important mechanisms for code re-uses, such as constructor chaining and method overloading. Use this course to delve into these important techniques that are required to write clean and maintainable Java code. Learn how to define methods with the same name but different signatures (i.e., different order and type of input arguments), invoke overloaded methods, and add constructors to a class. This course will also enable you to use the 'this' keyword to invoke multiple constructors, also known as constructor chaining. By the time you are done with this course, you will have the skills to use important code re-use mechanisms such as method overloading and constructor chaining in java.
WHAT YOU WILL LEARN
-
Discover the key concepts covered in this courseImplement return values and types correctlyCreate objects of a java class and use getters and setters to edit fieldsOverload methods with the same name in javaRecall how overloaded methods work and how they can invoke one anotherUse the default, no-argument constructor to create objects
-
Initialize fields in constructor definitionsCreate and use parameterized constructors in javaCreate multiple constructors with different signaturesInitialize fields using the 'this' keywordReuse code using constructor chainingSummarize the key concepts covered in this course
IN THIS COURSE
-
1m 51sExplore how to define methods with the same name but different signatures. You’ll see how overloaded methods can invoke each other and how it’s not permissible to overload methods purely on the return type alone. You’ll also learn the correct way of adding constructors to a class. You’ll see how multiple constructors can invoke each other using the keyword. FREE ACCESS
-
10m 5sFurther explore methods in Java. You’ll remember that in Java every class must match the name of the Java file in which it is hosted. Onscreen, you’ll see a class called Employee, so it is in a file called Employee.java. You’ll see this Employee class is a public class. FREE ACCESS
-
10m 46sHere, you’ll watch a demo. In this demo, you’ll pick up where you left off in the last demo. You’ll continue experimenting with different types of methods inside your employee class. You’ll begin by deleting the unreachable statement on line 25. This causes the compiler error to go away. You’ll then reintroduce some other compiler Errors. incompatible types. FREE ACCESS
-
12mDiscover that methods are functions that are different inside a class and which operate on the member variables of that particular object of the class. Watch a demo, and continue working with methods as they’re an important building block of Java. You’ll switch back to your employee class, and return to the update method defined in the previous demo. FREE ACCESS
-
9m 28sHere, you’ll watch a demo. You ended the last demo on the subject of method overloading onscreen. Here, you have three overloaded versions of the update method in your employee.Java file. Java is perfectly fine with methods that have the same name, provided they differ in their signatures. You’ll switch over to the main.Java file and use some overloaded methods. FREE ACCESS
-
8m 20sHere, you’ll learn to understand and use default constructors. You’ll learn these are special methods that help create an object and bring it to life by assigning memory and values to fields and the state of the object. This demo will highlight the capabilities and finer points of working with constructors. You’ll start with the Project Explorer Open. FREE ACCESS
-
6m 38sContinue working with constructors of different types in Java. Set up a simple helper method called PrintCarInfo. This will help you examine the contents of different objects. This method is defined onscreen. It simply prints out the state of an object. This means it prints out the values of the four member variables contained within each object. FREE ACCESS
-
7m 22sExplore creating parameterized constructors. A parameterized constructor that takes in input arguments and assigns those input arguments to the values of the objects fields. Onscreen, you’ll see modified code. You can see this has the features of a constructor. First, it has the same name as the class. And, it has no return value. Constructors never have a return value. FREE ACCESS
-
9m 2sExplore overloading constructors. Take a look at overloaded constructors in your car.Java file. Notice the car class has no less than five constructors. Discover the default no argument constructor. It doesn't take in any input arguments and it simply prints out a message Default no - argument constructor. FREE ACCESS
-
6m 4sHere, you’ll learn to use ‘this’ keyword in field initializations. In the previous demo, you implemented all ordered and parameterized constructors and made use of those constructors to build and instantiate different objects of the class. There are some aspects of the implementations of those constructors that can be improved upon, and you’ll focus on those here. FREE ACCESS
-
8m 30sYou’ll learn to reuse code through constructor chaining in this video. This refers to the practice of having multiple overloaded constructors that accept differing numbers of input arguments. They then call each other to minimize copy-pasting of code. There are some guidelines and rules to be kept in mind while chaining constructors. You’ll explore those in this demo. FREE ACCESS
-
2m 10sHere, you’ll summarize what you’ve learned in this course. You’ve learned type-safety restrictions in Java. You then learned about method overloading. You learned how to invoke overloaded functions by specifying different input arguments, and learned you can’t define two different functions with the same name and signature. You also learned constructor chaining and the rules around this. FREE ACCESS
EARN A DIGITAL BADGE WHEN YOU COMPLETE THIS COURSE
Skillsoft is providing you the opportunity to earn a digital badge upon successful completion on some of our courses, which can be shared on any social network or business platform.
Digital badges are yours to keep, forever.