Presentation on theme: "Object Usage Review...again. Creating a new instance What is a reference variable? All objects except for primitive variables are reference variables."— Presentation transcript:
Creating a new instance What is a reference variable? All objects except for primitive variables are reference variables How do we create a new object? 1. Declare the reference variables 2. Assign the reference a new object 3. Use the word new and then a constructor Card myCard = new Card(“Ace”, “Spades”) Contact myContact = new Contact(“John”, “Doe”, “703-867- 5309”)
Using an object’s attribute/method Objects possess attributes and methods You access an object’s attributs and methods using the. myArray.length//accessing an attribute myCard.getCardValue()//accessing a method You may access attributes and methods if they are public inside the object Methods may or may not return something
Your consent to our cookies if you continue to use this website.