Presentation is loading. Please wait.

Presentation is loading. Please wait.

Agenda About Homework for BPJ lesson 15 Overloading constructor

Similar presentations


Presentation on theme: "Agenda About Homework for BPJ lesson 15 Overloading constructor"— Presentation transcript:

1 Agenda About Homework for BPJ lesson 15 Overloading constructor
Overloading methods Calling constructor/method Encapsulation Homework

2 Overloading constructor
Constructors can be overloaded to provide more options for instantiating an object. Dog() - default constructor { breed = “Huskie”; color = “black”; leg = 4; size= ‘S’; }

3 Overloading constructor
public Dog(String oBreed, String oColor) { breed = b; color = c; size = ‘L’; leg=4; } public Dog(String oBreed, String oColor, char oSize) { breed = oBreed; color = oColor; size = oSize;

4 How do we know which constructor is being called???
Dog aDog = new Dog(); Dog bDog = new Dog(“Terrier”, “brown”); Dog cDog = new Dog(“chihuahua”, “white”, ‘s’);

5 Overloading methods Same method name with different number of parameters. public void eating(){ System.out.println(“eating dog food.”); } public void eating(String aFood){ System.out.println(“eating ” + aFood);

6 BankAccount class Create a BankAccount class.
This class has the following instance variables: Balance, account number, password A constructor which have 3 parameters. This class has the following methods: getBalance() deposit() withdraw()

7 Encapsulation Protecting an object’s data from code outside the class.
Those instance variables marked as private. They can only be seen or modified through the use of public accessor and mutator methods. Try type in the Cube class(next slide) in Eclipse and create a main(), instantiate a Cube object and type in <object>. to see the display list

8 public class Cube{ private int length; public int breadth; private int height; public Cube() { length = 10; breadth = 10; height = 10; } public Cube(int l, int b, int h) { length = l; breadth = b; height = h; } public int getVolume() { return (length * breadth * height); } }

9 Homework BPJ Lesson 16 Project ..Gas mileage
Follow all the instructions to create an Automobile class and tester program


Download ppt "Agenda About Homework for BPJ lesson 15 Overloading constructor"

Similar presentations


Ads by Google