Course Hive
Search

Welcome

Sign in or create your account

Continue with Google
or
Learn OVERLOADED CONSTRUCTORS in 6 minutes! 🛠️
Play lesson

Java tutorial for beginners ☕ - Learn OVERLOADED CONSTRUCTORS in 6 minutes! 🛠️

5.0 (4)
40 learners

What you'll learn

This course includes

  • 12 hours of video
  • Certificate of completion
  • Access on mobile and TV

Summary

Keywords

Full Transcript

#java #javatutorial #javacourse public class Main { public static void main(String[] args) { // overloaded constructors = Allow a class to have multiple constructors // with different parameter lists. // Enable objects to be initialized in various ways. User user1 = new User("Spongebob"); User user2 = new User("Patrick", "[email protected]"); User user3 = new User("Sandy", "[email protected]", 27); User user4 = new User(); System.out.println(user1.username); System.out.println(user1.email); System.out.println(user1.age); System.out.println(user2.username); System.out.println(user2.email); System.out.println(user2.age); System.out.println(user3.username); System.out.println(user3.email); System.out.println(user3.age); System.out.println(user4.username); System.out.println(user4.email); System.out.println(user4.age); } } public class User { String username; String email; int age; User(){ this.username = "Guest"; this.email = "Not provided"; this.age = 0; } User(String username){ this.username = username; this.email = "Not provided"; this.age = 0; } User(String username, String email){ this.username = username; this.email = email; this.age = 0; } User(String username, String email, int age){ this.username = username; this.email = email; this.age = age; } }

Course Hive

Continue this lesson in the app

Install CourseHive on Android or iOS to keep learning while you move.

Related Courses

FAQs

Course Hive
Download CourseHive
Keep learning anywhere