Agenda About Homework for BPJ lesson 15 Overloading constructor

Slides:



Advertisements
Similar presentations
1 Classes, Encapsulation, Methods and Constructors (Continued) Class definitions Instance data Encapsulation and Java modifiers Method declaration and.
Advertisements

IMPLEMENTING CLASSES Chapter 3. Black Box  Something that magically does its thing!  You know what it does but not how.  You really don’t care how.
1 Class Constructor Is a specific method Used to initialize the class’s fields Having the same name as the declaring classclass Doesn’t have return type(even.
1 Using Classes and Working With Class Interfaces November 20, 2002 CSE103 - Penn State University Prepared by Doug Hogan.
Big Java by Cay Horstmann Copyright © 2009 by John Wiley & Sons. All rights reserved. Chapter Three - Implementing Classes.
CSM-Java Programming-I Spring,2005 Class Design Lesson - 4.
ECE122 L6: Problem Definition and Implementation February 15, 2007 ECE 122 Engineering Problem Solving with Java Lecture 6 Problem Definition and Implementation.
1 Classes and Objects Overview l Classes and Objects l Constructors l Implicit Constructors l Overloading methods this keyword l public, private and protected.
Constructors A constructor is a method that creates an object in Java. It does not return anything and it is not void. It’s only purpose is to create an.
CSM-Java Programming-I Spring,2005 Introduction to Objects and Classes Lesson - 1.
Writing Classes (Chapter 4)
BPJ444: Business Programming Using Java Classes and Objects Tim McKenna
Classes CS 21a: Introduction to Computing I First Semester,
ACO 101: Introduction to Computer Science Anatomy Part 2: Methods.
CSC 1051 – Data Structures and Algorithms I Dr. Mary-Angela Papalaskari Department of Computing Sciences Villanova University Course website:
CSC 1051 – Data Structures and Algorithms I Dr. Mary-Angela Papalaskari Department of Computing Sciences Villanova University Course website:
© A+ Computer Science - public Triangle() { setSides(0,0,0); } Constructors are similar to methods. Constructors set the properties.
Inheritance CSC 171 FALL 2004 LECTURE 18. READING Read Horstmann, Chapter 11.
1 Warm-Up Problem Just like with primitive data types (int, double, etc.), we can create arrays of objects. ex: bankAccount employees[100]; Problem: It’s.
JAVA Classes Review. Definitions Class – a description of the attributes and behavior of a set of computational objects Constructor – a method that is.
CSC 1051 – Data Structures and Algorithms I Dr. Mary-Angela Papalaskari Department of Computing Sciences Villanova University Course website:
Designing a Card Game Solitaire--Thirteens. Game.
CSC 1051 – Data Structures and Algorithms I Dr. Mary-Angela Papalaskari Department of Computing Sciences Villanova University Course website:
CSE 501N Fall ‘09 04: Introduction to Objects 08 September 2009 Nick Leidenfrost.
CMSC 150 CLASSES CS 150: Mon 6 Feb 2012 Images: Library of Congress.
© 2004 Pearson Addison-Wesley. All rights reserved September 14, 2007 Anatomy of a Method ComS 207: Programming I (in Java) Iowa State University, FALL.
ACM/JETT Workshop - August 4-5, : Defining Classes in Java.
Copyright by Scott GrissomCh 2 Class Definition Slide 1 Class Structure public class BankAccount{ fields constructor(s) methods } Sample Code Ticket Machine.
Bank Account Example public class BankAccount { private double balance; public static int totalAccounts = 0; public BankAccount() { balance = 0; totalAccounts++;
Inheritance and Subclasses CS 21a. 6/28/2004 Copyright 2004, by the authors of these slides, and Ateneo de Manila University. All rights reserved L16:
Software development For large and complex software use divide and conquer rule. Software design methods: Structured design Object-Oriented design.
Powerpoint slides from A+ Computer Science Modified by Mr. Smith for his course.
Non-Static Classes What is the Object of this lecture?
Monday, Jan 27, 2003Kate Gregory with material from Deitel and Deitel Week 4 Questions from Last Week Hand in Lab 2 Classes.
Topics Instance variables, set and get methods Encapsulation
CS 100Lecture71 CS100J Lecture 7 n Previous Lecture –Computation and computational power –Abstraction –Classes, Objects, and Methods –References and aliases.
OOP in C# - part 1 OOP in C#: –Object Interaction. –Inheritance and Polymorphism (next module). FEN 20121UCN Technology: Computer Science.
 An object is basically anything in the world that can be created and manipulated by a program.  Examples: dog, school, person, password, bank account,
Powerpoint slides from A+ Computer Science Modified by Mr. Smith for his course.
Basic Class Structure. Class vs. Object class - a template for building an object –defines the instance data that the object will hold –defines instance.
Programming in Java Transitioning from Alice. Becomes not myFirstMethod but …. public static void main (String[] arg) { // code for testing classes goes.
INTRODUCTION TO CLASSES & OBJECTS CREATING CLASSES USING C#
Java 5 Class Anatomy. User Defined Classes To this point we’ve been using classes that have been defined in the Java standard class library. Creating.
Objects as a programming concept
Lecture 3 John Woodward.
Examples of Classes & Objects
Computing with C# and the .NET Framework
Creating Your OwnClasses
public class BankAccount{
CLASS DEFINITION (> 1 CONSTRUCTOR)
Chapter Three - Implementing Classes
Java Programming with BlueJ
Ch 4: Writing Classes Java Software Solutions Foundations of Program Design Sixth Edition by Lewis & Loftus Coming up: Classes and Objects.
OBJECT ORIENTED PROGRAMMING II LECTURE 8 GEORGE KOUTSOGIANNAKIS
Classes & Objects: Examples
Classes, Encapsulation, Methods and Constructors (Continued)
More on Classes and Objects
Implementing Classes Chapter 3.
© A+ Computer Science - OOP © A+ Computer Science -
Class Everything if Java is in a class. The class has a constructor that creates the object. public class ClassName private Field data (instance variables)
Agenda About Homework for BPJ lesson 36 About practice of last class
CS100J Lecture 7 Previous Lecture This Lecture Java Constructs
JAVA CLASSES.
Instance Method – CSC142 Computer Science II
By Rajanikanth B OOP Concepts By Rajanikanth B
Classes CS 21a: Introduction to Computing I
Introduction to Object-Oriented Programming
Classes and Objects CGS3416 Spring 2019.
CSG2H3 Object Oriented Programming
Introduction to Computer Science and Object-Oriented Programming
Presentation transcript:

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

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’; }

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;

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’);

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);

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()

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

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); } }

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