Consider the following Which of the following will cause a java.lang.ClassCastException? a)Alpha a = x; b)Foo f= (Delta)x; c)Foo f= (Alpha)x; d)Beta b.

Slides:



Advertisements
Similar presentations
Continuation of chapter 6…. Nested while loop A while loop used within another while loop is called nested while loop. Q. An illustration to generate.
Advertisements

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.
SCJP 6.0 Lecturer Fuh-Gwo Chen
Numeric literals and named constants. Numeric literals Numeric literal: Example: A numeric literal is a constant value that appears in a Java program.
CSE115: Introduction to Computer Science I Dr. Carl Alphonce 219 Bell Hall Office hours: M-F 11:00-11:
Java Generics.
Lecture 27 Exam outline Boxing of primitive types in Java 1.5 Generic types in Java 1.5.
Liang, Introduction to Java Programming, Sixth Edition, (c) 2007 Pearson Education, Inc. All rights reserved L13 (Chapter 21) Generics.
1 More on Inheritance Overview l Object: The father of all classes l Casting and Classes l Object Cloning l Importance of Cloning.
Java Generics. 2 The Dark Ages: Before Java 5 Java relied only on inclusion polymorphism  A polymorphism code = Using a common superclass Every class.
Generics OOP Tirgul What is it good for ? Stack myStack = new Stack() ; // old version (1.4.2) myStack.push(new Integer(0)) ; int x = ((Integer)
Creating Generic Classes. Introduction Java Generics were added to allow for type- safe collections and eliminate the need for burdensome, code-cluttering.
Primitive Data Types byte, short, int, long float, double char boolean Are all primitive data types. Primitive data types always start with a small letter.
Exam Objective : Legal return types PRESENTED BY : SRINIVAS VG.
CPSC150 Interfaces Chapter CPSC150 Inheritance Review No different than any other class. Has no access to or information about subclasses class.
1 תוכנה 1 ג ' אווה תרגול י " ג – סיכום הסיכומים ליאור שפירא ומתי שמרת.
COMP 14: Intro. to Intro. to Programming May 23, 2000 Nick Vallidis.
Copyright © 2007 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Starting Out with Java From Control Structures through Data Structures by.
Computer Programming Lab(5).
P Object type and wrapper classes p Object methods p Generic classes p Interfaces and iterators Generic Programming Data Structures and Other Objects Using.
OVERRIDING/OVERLOADING Srinivas. EXAM OBJECTIVES  Given a code example, determine if a method is correctly overriding or overloading another method,
INPUT/OUTPUT STATEMENT ADDITION SLIDES. Console.ReadLine() – Use to get the input (String) from user Convert string to other data type – int.Parse() 
Chapter 21 Generics 1. Generics - Overview Generic Methods specify a set of related methods Generic classes specify a set of related types Software reuse.
Effective Java: Generics Last Updated: Spring 2009.
Processes & Threads Bahareh Goodarzi. Single & Multiple Thread of control code files data code files data.
Chapter 2: Java Fundamentals
CSE 143 Lecture 23 Polymorphism; the Object class read slides created by Marty Stepp and Ethan Apter
Java Generics Compiled from Core Java Technologies Tech Tips By Billy B. L. Lim.
Mixing integer and floating point numbers in an arithmetic operation.
1 Creating Web Services Presented by Ashraf Memon Hands-on Ghulam Memon, Longjiang Ding.
COP3502 Programming Fundamentals for CIS Majors 1 Instructor: Parisa Rashidi.
Chapter 5 Objects and Classes Inheritance. Solution Assignments 3 & 4 Review in class…..
ICBT  Basura Ramanayaka  Eshani werapitiya  Hasitha Dananjaya.
Liang, Introduction to Java Programming, Tenth Edition, (c) 2013 Pearson Education, Inc. All rights reserved. 1 Chapter 19 Generics.
Chapter 4 Generic Vector Class. Agenda A systemic problem with Vector of Object – Several approaches at a solution – Generic structures Converting classes.
Method OverloadingtMyn1 Method overloading Methods of the same name can be declared in the same class, as long as they have different sets of parameters.
INPUT/OUTPUT STATEMENT ADDITION SLIDES. Console.ReadLine() – Use to get the input (String) from user Convert string to other data type – int.Parse() 
import java.util.Scanner; class myCode { public static void main(String[] args) { Scanner input= new Scanner(System.in); int num1; System.out.println(“Enter.
JOptionPane. Import javax.swing.JOptionPane Use showInputDialog() for input. Only string values can be input. To convert an input value from a string.
1 Chapter 21 Generics. 2 Objectives F To use generic classes and interfaces (§21.2). F To declare generic classes and interfaces (§21.3). F To understand.
1 Lecture # 2. * Introducing Programming with an Example * Identifiers, Variables, and Constants * Primitive Data Types * Byte, short, int, long, float,
Sun Upgrade Exam for the Sun Certified Java Programmer. SE 6.0 Thousands of IT Professionals before you have already passed their certification.
Comp1004: Building Better Objects I Methods. Coming up Methods and Parameters – Why Parameterise? – Call by value, call by reference Return Types – Methods.
 It is a pure oops language and a high level language.  It was developed at sun microsystems by James Gosling.
New Java Features Advanced Programming Techniques.
Variable scope. Variable Scope Variables do not live forever. Failing to take that into account leads to problems. Let's look at an example. Let's write.
AP Computer Science Exam Review Number Systems Binary.
Objects Real and Java COMP T1 3
Modern Programming Tools And Techniques-I
using System; namespace Demo01 { class Program
CompSci 230 S Programming Techniques
Lecture 17: Polymorphism (Part II)
Computer Programming Methodology Input and While Loop
Computer Programming Methodology Luminance
Functions Used to write code only once Can use parameters.
Explicit and Implicit Type Changes
More inheritance, Abstract Classes and Interfaces
Introduction to Java Programming
CS 302 Week 8 Jim Williams, PhD.
References and Objects
class PrintOnetoTen { public static void main(String args[]) {
Generics, Lambdas, Reflections
Lecture 18: Polymorphism (Part II)
Sampath Kumar S Assistant Professor, SECE
Developing Java Applications with NetBeans
Developing Java Applications with NetBeans
A Few Review Questions Dan Fleck CS211 Fall 2007.
Subtype Substitution Principle
ArrayLists Readings: 10.1 (pg. 559 – 571).
Presentation transcript:

Consider the following Which of the following will cause a java.lang.ClassCastException? a)Alpha a = x; b)Foo f= (Delta)x; c)Foo f= (Alpha)x; d)Beta b = (Beta)(Alpha)x; 1 interface Foo {} class Alpha implements Foo { } class Beta extends Alpha {} class Delta extends Beta { public static void main(String[] args) { Beta x = new Beta(); // insert code here } } B

Consider the following What will happen …? p6 = (CollegeStudent) p3; p7 = (CollegeStudent) p2; 2 class Person { … } class Student extends Person { … } class CollegeStudent extends Student { … } Person p1 = new Person("Michael"); Student p2 = new Student("Dick"); Student p3 = new CollegeStudent("Peter"); CollegeStudent p6, p7; No error (compile ok, run time ok) Run time error if (p2 instanceof CollegeStudent) p7 = (CollegeStudent) p2;

Integer Vs int (Wrapper class) Which of the following create an Integer object correctly? Integer intObj1 = new Integer(23); Integer intObj1 = 23; How to convert an Integer object to an int primitive type? 3 autoboxing int x = intObj1.intValue();