CSC 113: Computer programming II

Slides:



Advertisements
Similar presentations
1 - Recursion on linked lists Lecture 7 ADS2 Lecture 7.
Advertisements

Slides prepared by Rose Williams, Binghamton University ICS201 Lecture 4 : Polymorphism King Fahd University of Petroleum & Minerals College of Computer.
OO Programming in Java Objectives for today: Overriding the toString() method Polymorphism & Dynamic Binding Interfaces Packages and Class Path.
The Point Class public class Point { public double x; public double y; public Point(double x0, double y0) { x = x0; y = y0; } public double distance(Point.
Chapter 1 Object-Oriented Concepts. A class consists of variables called fields together with functions called methods that act on those fields.
Copyright 2008 by Pearson Education Building Java Programs Chapter 8 Lecture 8-3: Encapsulation, toString reading: self-checks: #13-18,
Java Programming 2 Dr. Priti Srinivas Sajja Introductory concepts of java programming as specified in PGDCA 203:Object Technology, S P University.
Topic 10 Java Memory Management. 1-2 Memory Allocation in Java When a program is being executed, separate areas of memory are allocated for each class.
Problem Solving 5 Using Java API for Searching and Sorting Applications ICS-201 Introduction to Computing II Semester 071.
METHOD OVERRIDING Sub class can override the methods defined by the super class. Overridden Methods in the sub classes should have same name, same signature.
METHOD OVERRIDING 1.Sub class can override the methods defined by the super class. 2.Overridden Methods in the sub classes should have same name, same.
1 Inheritance Chapter 9. 2 Module Outcomes To develop a subclass from a superclass through inheritance To invoke the superclass ’ s constructors and methods.
5/2/2015 Good Java Programming 1 Bigram: group/word of 2 letters java.util.Set: A collection that contains no duplicate elements.  sets contain no pair.
CS 211 Inheritance AAA.
Java Inheritance. What is inherited A subclass inherits variables and methods from its superclass and all of its ancestors. The subclass can use these.
CS 106 Introduction to Computer Science I 04 / 16 / 2010 Instructor: Michael Eckmann.
Chapter 8 User-Defined Classes and ADTs. Chapter Objectives Learn about classes Learn about private, protected, public, and static members of a class.
Class template Describing a generic class Instantiating classes that are type- specific version of this generic class Also are called parameterized types.
Chapter 8: User-Defined Classes and ADTs J ava P rogramming: From Problem Analysis to Program Design, From Problem Analysis to Program Design, Second Edition.
Inheritance Part II. Lecture Objectives To learn about inheritance To understand how to inherit and override superclass methods To be able to invoke superclass.
Vocabulary Key Terms polymorphism - Selecting a method among many methods that have the same name. subclass - A class that inherits variables and methods.
Writing a Class (defining a data-type). Create a new project : Project (uncheck the “Create Main Class”)
Inheritance One of the biggest advantages of object-oriented design is that of inheritance. A class may be derived from another class, the base class.
Java Class Syntax CSIS 3701: Advanced Object Oriented Programming.
CPSC1301 Computer Science 1 Chapter 11 Creating Classes part 1.
Java Classes Using Java Classes Introduction to UML.
Programming Pillars Introduction to Object- Oriented Programming.
Georgia Institute of Technology Creating Classes part 1 Barb Ericson Georgia Institute of Technology Oct 2005.
© A+ Computer Science - public Triangle() { setSides(0,0,0); } Constructors are similar to methods. Constructors set the properties.
AP Computer Science A – Healdsburg High School 1 Interfaces, Abstract Classes and the DanceStudio - Similarities and Differences between Abstact Classes.
Chapter 8: User-Defined Classes and ADTs
CS442: ADVANCED PROGRAMMING USING JAVA Lab 6: Classes and objects Computer Science Department.
JAVA Classes Review. Definitions Class – a description of the attributes and behavior of a set of computational objects Constructor – a method that is.
1 Introduction to Computer Science for Majors II CPSC 233, Winter 2013 CPSC 233, winter 2013 Tutorial 14, Mar 27/28, 2013.
OOP with Objective-C Categories, Protocols and Declared Properties.
Inheritance Inheritance is the process of extending the functionality of a class by defining a new class that inherit,all the features of extending class.
CSC142 NN 1 CSC 142 Overriding methods from the Object class: equals, toString.
Data Structures Using Java1 Chapter 1 Software Engineering Principles and Java Classes.
COMP Inheritance and Polymorphism Yi Hong June 09, 2015.
PYTHON FUNCTIONS. What you should already know Example: f(x) = 2 * x f(3) = 6 f(3)  using f() 3 is the x input parameter 6 is the output of f(3)
Comp1004: Inheritance II Polymorphism. Coming up Inheritance Reminder Overriding methods – Overriding and substitution Dynamic Binding Polymorphism –
CSC 1051 – Data Structures and Algorithms I Dr. Mary-Angela Papalaskari Department of Computing Sciences Villanova University Course website:
Java Programming: Guided Learning with Early Objects Chapter 9 Inheritance and Polymorphism.
Object-Oriented Concepts
Overriding Method.
Software Development Java Classes and Methods
CSC 205 Java Programming II
Designing for Inheritance
Recitation 6 Inheritance.
User-Defined Classes and ADTs
Inheritance Basics Programming with Inheritance
The super Reference Constructors cannot be used in child classes, even though they have public visibility Yet we often want to use the parent's constructor.
An Introduction to Java – Part II
Methods (toString, equals)
ITunes Lab Copyright © 2012 Pearson Education, Inc.
Chapter 8: User-Defined Classes and ADTs
Computer Programming with JAVA
Chapter 11 Inheritance and Polymorphism
Recitation 7 October 7, 2011.
User-Defined Classes and ADTs
Barb Ericson Georgia Institute of Technology Oct 2005
Java Inheritance.
Chapter 8 Classes User-Defined Classes and ADTs
© A+ Computer Science - OOP Pieces © A+ Computer Science -
Instance Method – CSC142 Computer Science II
Kinds of methods accessor: A method that lets clients examine object state. Examples: distance, distanceFromOrigin often has a non-void return type mutator: A.
If-statements & Indefinite Loops
Chapter 11 Inheritance and Polymorphism Part 1
CSC 205 Java Programming II
Presentation transcript:

CSC 113: Computer programming II Objects and methods CSC 113: Computer programming II

The Method toString public value-returning method Takes no parameters Returns address of a String object Output using print, println, printf methods Default definition creates String with name of object’s class name followed by hash code of object

The Method toString Implementing toString method in java is done by overriding the Object’s toString method. The java toString() method is used when we need a string representation of an object. It is defined in Object class. This method can be overridden to customize the String representation of the Object.

Object toString() method : PointCoordinates@119c082 PointCoordinates@119c082 testing

When you run the ToStringDemo2 program, the output is: X=10 Y=10 X=10 Y=10 testing

36)

36)

this(. ) - Calls another constructor in same class this(...) - Calls another constructor in same class. Often a constructor with few parameters will call a constructor with more parameters, giving default values for the missing parameters. Use this to call other constructors in the same class.