Multiple Choice Solutions True/False a c b e d   T F.

Slides:



Advertisements
Similar presentations
Object Oriented Programming with Java
Advertisements

Java Review Interface, Casting, Generics, Iterator.
INTERFACES IN JAVA 1.Java Does not support Multiple Inheritance directly. Multiple inheritance can be achieved in java by the use of interfaces. 2.We need.
Module 8 “Polymorphism and Inheritance”. Outline Understanding Inheritance Inheritance Diagrams Constructors in Derived Classes Type Compatibility Polymorphism.
CS 106 Introduction to Computer Science I 04 / 11 / 2008 Instructor: Michael Eckmann.
Inheritance Inheritance Reserved word protected Reserved word super
CS 106 Introduction to Computer Science I 11 / 26 / 2007 Instructor: Michael Eckmann.
CSE 143 Lecture 22: Advanced List Implementation (ADTs; interfaces; abstract classes; inner classes; generics; iterators)
Week 4 Recap CSE 115 Spring Formal Parameter Lists Comma-separated list of formal parameters Formal parameters are listed giving the type of the.
CS 106 Introduction to Computer Science I 04 / 16 / 2010 Instructor: Michael Eckmann.
June 1, 2000 Object Oriented Programming in Java (95-707) Java Language Basics 1 Lecture 3 Object Oriented Programming in Java Language Basics Classes,
CPSC150 Abstract Classes and Interfaces Chapter 10.
©TheMcGraw-Hill Companies, Inc. Permission required for reproduction or display. Chapter 10 *Arrays with more than one dimension *Java Collections API.
Building Java Programs Inner classes, generics, abstract classes reading: 9.6, 15.4,
Abstract classes and Interfaces. Abstract classes.
Polymorphism & Interfaces
Introduction to Object Oriented Programming. Object Oriented Programming Technique used to develop programs revolving around the real world entities In.
Method Overriding Remember inheritance: when a child class inherits methods, variables, etc from a parent class. Example: public class Dictionary extends.
APCS Java AB 2004 Review of CS1 and CS2 Review for AP test #1 Sources: 2003 Workshop notes from Chris Nevison (Colgate University) AP Study Guide to go.
Chap. 1 Classes, Types, and Objects. How Classes Are Declared [ ] class [extends ] [implements,, … ] { // class methods and instance variable definitions.
Chapter 2 Introducing Interfaces Summary prepared by Kirk Scott.
Inheritance in the Java programming language J. W. Rider.
Tuc Goodwin  Object and Component-Oriented Programming  Classes in C#  Scope and Accessibility  Methods and Properties  Nested.
Chapter 3 Inheritance and Polymorphism Goals: 1.Superclasses and subclasses 2.Inheritance Hierarchy 3.Polymorphism 4.Type Compatibility 5.Abstract Classes.
CSE 143 Lecture 24 Advanced collection classes (ADTs; abstract classes; inner classes; generics; iterators) read 11.1, 9.6, , slides.
AP Computer Science edition Review 1 ArrayListsWhile loopsString MethodsMethodsErrors
MIT AITI 2004 – Lecture 13 Abstract Classes and Interfaces.
Interfaces Chapter 9. 9 Creating Interfaces An interface is a contract. Every class that implements the interface must provide the interface’s defined.
PROGRAMMING IN C#. Collection Classes (C# Programming Guide) The.NET Framework provides specialized classes for data storage and retrieval. These classes.
1 Inheritance Reserved word protected Reserved word super Overriding methods Class Hierarchies Reading for this lecture: L&L 9.1 – 9.4.
Side effects A side effect is anything that happens in a method other than computing and/or returning a value. Example: public class hello { public int.
Method Overriding Remember inheritance: when a child class inherits methods, variables, etc from a parent class. Example: public class Dictionary extends.
Quick Review of OOP Constructs Classes:  Data types for structured data and behavior  fields and methods Objects:  Variables whose data type is a class.
Array Size Arrays use static allocation of space. That is, when the array is created, we must specify the size of the array, e.g., int[] grades = new int[100];
Classes - Intermediate
Constructors A constructor is a method that has the same name as the class itself It is automatically called when an object is instantiated (in other words,
Interfaces. In order to work with a class, you need to understand the public methods  methods, return types,…  after you instantiate, what can you do.
Terms and Rules II Professor Evan Korth New York University (All rights reserved)
POLYMORPHISM Chapter 6. Chapter Polymorphism  Polymorphism concept  Abstract classes and methods  Method overriding  Concrete sub classes and.
OOP Basics Classes & Methods (c) IDMS/SQL News
Structured Programming Dr. Atif Alhejali Lecture 4 Modifiers Parameters passing 1Structured Programming.
This In Java, the keyword this allows an object to refer to itself. Or, in other words, this refers to the current object – the object whose method or.
Mid-Year Review. Coding Problems In general, solve the coding problems by doing it piece by piece. Makes it easier to think about Break parts of code.
COP INTERMEDIATE JAVA Inheritance, Polymorphism, Interfaces.
CSC 243 – Java Programming, Spring, 2014 Week 4, Interfaces, Derived Classes, and Abstract Classes.
VISUAL C++ PROGRAMMING: CONCEPTS AND PROJECTS Chapter 7A Arrays (Concepts)
Lecture 5:Interfaces and Abstract Classes Michael Hsu CSULA.
Comp1004: Object Oriented Design I Abstract Classes and Interfaces.
Inheritance Notes: Using Object Oriented Design
Haskell Chapter 2.
Interface.
Agenda Warmup AP Exam Review: Litvin A2
Interfaces Professor Evan Korth.
Wrapper Classes ints, doubles, and chars are known as primitive types, or built-in types. There are no methods associated with these types of variables.
Interfaces.
Interface.
Conditional Statements
CSE 143 Lecture 27: Advanced List Implementation
Lecture 26: Advanced List Implementation
Interfaces.
Abstract Class As per dictionary, abstraction is the quality of dealing with ideas rather than events. For example, when you consider the case of ,
Advanced Java Programming
Unit 3 Test: Friday.
CSE 501N Fall ‘09 13: Interfaces and Multiple Representation
Java Inheritance.
Chapter 14 Abstract Classes and Interfaces
2009 Test Key.
CSE 143 Lecture 21 Advanced List Implementation
Corresponds with Chapter 5
INTERFACES Explained By: Sarbjit Kaur. Lecturer, Department of Computer Application, PGG.C.G., Sector: 42, Chandigarh.
Presentation transcript:

Multiple Choice Solutions True/False a c b e d   T F

this In Java, the keyword this allows an object to refer to itself. Or, in other words, this refers to the current object – the object whose method or constructor is being called. Example: public class Chess { // more code up here public void capture (Piece x) if (x.equals(this)) return false; }

Another this example public class Sample { public int x = 0; public int y = 0; public Sample (int x, int y) { this.x = x; this.y = y; } // now, there are local copies of the parameters x and y in this class.

The List Interface In addition to the Comparable interface, another interface that you must be aware of is the List interface. ArrayList is a class that implements List. We will soon learn about polymorphism, which is used when a parent class or interface has a method that gets overridden by its child/subclass. For now, all you need to know about List is that it’s an interface that gets implemented by ArrayList.

Abstract Class We know what an interface is – a class that contains abstract (empty) methods, and can also contain constants. An abstract class is similar, but one major difference is that it can contain methods that actually contain code. In other words, an abstract class can implement methods, while an interface cannot. Like an interface, an abstract class CANNOT be instantiated. (In other words, you cannot, in a client, create an object of an abstract class.)

public abstract class Sample2 { public int sum (int num1, int num2) return (num1 + num2) } public char something(int z); /* note that this abstract class contains a method with actual code in its body, which is not allowed in an interface. */

Interface vs. Abstract Class You cannot instantiate (create an object of) an abstract class, but you can extend an abstract class, and then use its methods. So, what’s the point of an abstract class? Why not just use an interface, if you want to create a “blueprint” that programmers must follow? The answer is: If a bunch of programmers will be using the same method, in the same way, then it makes more sense to put this method in an abstract class and have them extend this class. But, if those programmers will be using the same method signature, but writing code for the method body in different ways, then it makes more sense to put that method in an interface and have them implement that interface.

We learned yesterday that all methods and variables in an interface must be public. (it wouldn’t make sense to have a private method in an interface, because where would this empty method be called from?) An abstract class, however, can have private methods and variables.

for-each loop When going through (“traversing”) every element in an array or ArrayList, an efficient way to do so is by using a for-each loop. Syntax: for (type element : array) { // body of loop }

Using for-each loops with 2D arrays Remember, a 2D array is really just a 1D array in which each element is itself a 1D array. This is important, because when using a for-each loop with a 2D array, you first place each row of the table into a 1D array. Then, with a nested for-each loop, you assign each element of each row into that 1D array. Demo: ForEachLoopDemo

Static Methods A static method is a method that can be called by using the name of the class itself. You do not need to create an object in order to call the method. We have been using static methods for a long time: SavitchIn.readLine(); Math.pow(), etc. This explains why you don’t have to “connect” (create an object of) the SavitchIn class in order to use it. Open: StaticMethodClass, StaticMethodClient