Polymorphism 2/12/2018. Which statement is correct about overriding private methods in the super class?

Similar documents
CS111: PROGRAMMING LANGUAGE II

CS111: PROGRAMMING LANGUAGE II

OVERRIDING. 7/11/2015 Budditha Hettige 82

Inheritance. Lecture 11 COP 3252 Summer May 25, 2017

Object Oriented Programming. Java-Lecture 11 Polymorphism

Java Object Oriented Design. CSC207 Fall 2014

Lecture Contents CS313D: ADVANCED PROGRAMMING LANGUAGE. What is Inheritance?

Programming II (CS300)

CS313D: ADVANCED PROGRAMMING LANGUAGE

More On inheritance. What you can do in subclass regarding methods:

Programming II (CS300)

Inheritance. Transitivity

JAVA MOCK TEST JAVA MOCK TEST II

INHERITANCE. Spring 2019

CS 251 Intermediate Programming Inheritance

Lecture 18 CSE11 Fall 2013 Inheritance

Java Inheritance. Written by John Bell for CS 342, Spring Based on chapter 6 of Learning Java by Niemeyer & Leuck, and other sources.

CS-202 Introduction to Object Oriented Programming

Inheritance. Benefits of Java s Inheritance. 1. Reusability of code 2. Code Sharing 3. Consistency in using an interface. Classes

What is Inheritance?

Inheritance, and Polymorphism.

Object Oriented Features. Inheritance. Inheritance. CS257 Computer Science I Kevin Sahr, PhD. Lecture 10: Inheritance

CS313D: ADVANCED PROGRAMMING LANGUAGE

Contents. I. Classes, Superclasses, and Subclasses. Topic 04 - Inheritance

Superclasses / subclasses Inheritance in Java Overriding methods Abstract classes and methods Final classes and methods

Chapter 14 Abstract Classes and Interfaces

Arrays Classes & Methods, Inheritance

Programming Language Concepts Object-Oriented Programming. Janyl Jumadinova 28 February, 2017

INHERITANCE & POLYMORPHISM. INTRODUCTION IB DP Computer science Standard Level ICS3U. INTRODUCTION IB DP Computer science Standard Level ICS3U

CS Programming I: Inheritance

CREATED BY: Muhammad Bilal Arslan Ahmad Shaad. JAVA Chapter No 5. Instructor: Muhammad Naveed

Object-Oriented Concepts

IT101. Inheritance, Encapsulation, Polymorphism and Constructors

Chapter 10 Classes Continued. Fundamentals of Java

CS-140 Fall 2017 Test 1 Version Practice Practice for Nov. 20, Name:

PROGRAMMING LANGUAGE 2

Inheritance. Inheritance Reserved word protected Reserved word super Overriding methods Class Hierarchies Reading for this lecture: L&L

Abstract Classes. Abstract Classes a and Interfaces. Class Shape Hierarchy. Problem AND Requirements. Abstract Classes.

Records. ADTs. Objects as Records. Objects as ADTs. Objects CS412/CS413. Introduction to Compilers Tim Teitelbaum. Lecture 15: Objects 25 Feb 05

Inheritance and Encapsulation. Amit Gupta

Object-Oriented Design

Chapter 5 Object-Oriented Programming

Lesson 10. Work with Interfaces and Abstract Classes. Copyright all rights reserved

ECE 122. Engineering Problem Solving with Java

Inheritance -- Introduction

ITI Introduction to Computing II

Java Programming Lecture 7

OOPS Viva Questions. Object is termed as an instance of a class, and it has its own state, behavior and identity.

CS260 Intro to Java & Android 03.Java Language Basics

ITI Introduction to Computing II

What are the characteristics of Object Oriented programming language?

Object Orientated Programming Details COMP360

OOPs Concepts. 1. Data Hiding 2. Encapsulation 3. Abstraction 4. Is-A Relationship 5. Method Signature 6. Polymorphism 7. Constructors 8.

Lecture 4: Extending Classes. Concept

Unit 4 - Inheritance, Packages & Interfaces

CS111: PROGRAMMING LANGUAGE II

Inheritance and Polymorphism

HAS-A Relationship. Association is a relationship where all objects have their own lifecycle and there is no owner.

EXERCISES SOFTWARE DEVELOPMENT I. 09 Objects: Inheritance, Polymorphism and Dynamic Binding 2018W

Argument Passing All primitive data types (int etc.) are passed by value and all reference types (arrays, strings, objects) are used through refs.

CS304- Object Oriented Programming LATEST SOLVED MCQS FROM FINALTERM PAPERS. MC

Motivations. Chapter 13 Abstract Classes and Interfaces

Chapter 5. Inheritance

The Object Class. java.lang.object. Important Methods In Object. Mark Allen Weiss Copyright 2000

Polymorphism and Interfaces. CGS 3416 Spring 2018

More on Inheritance. Interfaces & Abstract Classes

Abstract Classes and Interfaces

Chapter 12. OOP: Creating Object- Oriented Programs. McGraw-Hill. Copyright 2011 by The McGraw-Hill Companies, Inc. All Rights Reserved.

Inheritance in java is a mechanism in which one object acquires all the properties and behaviors of parent object.

Java How to Program, 8/e

QUESTIONS FOR AVERAGE BLOOMERS

More on Objects in JAVA TM

Inheritance. One class inherits from another if it describes a specialized subset of objects Terminology:

Inheritance and Polymorphism

Overview of OOP. Dr. Zhang COSC 1436 Summer, /18/2017

Overview. Lecture 7: Inheritance and GUIs. Inheritance. Example 9/30/2008

Lecture 36: Cloning. Last time: Today: 1. Object 2. Polymorphism and abstract methods 3. Upcasting / downcasting

Name Return type Argument list. Then the new method is said to override the old one. So, what is the objective of subclass?

CLASSES AND OBJECTS IN JAVA

Boaz Kantor Introduction to Computer Science IDC Herzliya ( Reichman )

INTERFACES. 24-Dec-10 INTERFACES VS. INHERITANCE. Boaz Kantor Introduction to Computer Science IDC Herzliya ( Reichman ) Interfaces: Inheritance:

Announcement. Agenda 7/31/2008. Polymorphism, Dynamic Binding and Interface. The class will continue on Tuesday, 12 th August

Inheritance and Polymorphism. CS180 Fall 2007

The software crisis. code reuse: The practice of writing program code once and using it in many contexts.

Inheritance (Outsource: )

CS200: Advanced OO in Java

Graphical Interface and Application (I3305) Semester: 1 Academic Year: 2017/2018 Dr Antoun Yaacoub

Object Fundamentals. Kenneth M. Anderson University of Colorado, Boulder CSCI 4448/6448 Lecture 2 08/30/2007

Object Oriented Programming is a programming method that combines: Advantage of Object Oriented Programming

Chapter 9 Inheritance

Homework 6. Yuji Shimojo CMSC 330. Instructor: Prof. Reginald Y. Haseltine

CMSC131. Inheritance. Object. When we talked about Object, I mentioned that all Java classes are "built" on top of that.

OOP in Java Review. CS356 Object-Oriented Design and Programming October 1, 2014

CSCI-142 Exam 1 Review September 25, 2016 Presented by the RIT Computer Science Community

Inheritance (continued) Inheritance

Comp 249 Programming Methodology

ECE 122. Engineering Problem Solving with Java

Enhanced Entity- Relationship Models (EER)

CO Java SE 8: Fundamentals

Super-Classes and sub-classes

Transcription:

Which statement is correct about overriding private methods in the super class? Peer Instruction Polymorphism Please select the single correct answer. A. Any derived class can override private methods in the base class. B. Private methods can never be overridden by a derived class. C. Any derived class in the same package can override private methods. D. Overriding a private method hides the base class version. E. Overriding private methods is allowed but highly discouraged. cs165: Peer 3 - Polymorphism - Spring Semester 2017 Question - 1 Which statement is correct about overriding private methods in the super class? Please select the single correct answer. A. Any derived class can override private methods in the base class. B. Private methods can never be overridden by a derived class. C. Any derived class in the same package can override private methods. D. Overriding a private method hides the base class version. E. Overriding private methods is allowed but highly discouraged. Which is printed when the following code with getclass calls is executed? Person p = new Employee(); Employee e = new Employee(); System.out.println(p.getClass()+, +e.getclass()); A. class Person,class Employee B. class Employee,class Employee C. class Person,class Person D. class Employee,class Person cs165: Peer 3 - Polymorphism - Spring Semester 2017 Question - 2 cs165: Peer 3 - Polymorphism - Spring Semester 2017 Question - 3 1

Which is printed when the following code with getclass calls is executed? Person p = new Employee(); Employee e = new Employee(); System.out.println(p.getClass()+, +e.getclass()); A. class Person,class Employee B. class Employee,class Employee C. class Person,class Person D. class Employee,class Person Which of the following is an incorrect statement about access modifiers? A. Public means methods and attributes accessible from anywhere. B. Private means accessible only from within the class where defined. C. Protected has a different meaning for methods and attributes. D. Protected means accessible from same package or any subclass. E. Default means no other access modifier has been specified. cs165: Peer 3 - Polymorphism - Spring Semester 2017 Question - 4 cs165: Peer 3 - Polymorphism - Spring Semester 2017 Question - 5 Which of the following is an incorrect statement about access modifiers? A. Public means methods and attributes accessible from anywhere. B. Private means accessible only from within the class where defined. C. Protected has a different meaning for methods and attributes. D. Protected means accessible from same package or any subclass. E. Default means no other access modifier has been specified. Which statement about the final keyword is incorrect? A. When final is applied to a class variable, it cannot be modified. B. When final is applied to a local variable, it cannot be modified. C. When final is applied to a parameter, it cannot be modified. D. When final is applied to a method, it cannot be overridden. E. When final is applied to a class, it can be extended but not instantiated. cs165: Peer 3 - Polymorphism - Spring Semester 2017 Question - 6 cs165: Peer 3 - Polymorphism - Spring Semester 2017 Question - 7 2

Which statement about the final keyword is incorrect? A. When final is applied to a class variable, it cannot be modified. B. When final is applied to a local variable, it cannot be modified. C. When final is applied to a parameter, it cannot be modified. D. When final is applied to a method, it cannot be overridden. E. When final is applied to a class, it can be extended but not instantiated. On to the lecture cs165: Peer 3 - Polymorphism - Spring Semester 2017 Question - 8 cs165: Peer 3 - Polymorphism - Spring Semester 2017 Question - 9 Peer Instruction Abstract Classes and Interfaces Select the incorrect definition of an abstract method in Java. A. All of the methods that reside in an abstract class are by definition abstract. B. All of the methods in a Java interface are abstract methods since they cannot have an implementation. C. An abstract method cannot have an implementation until another class overrides it. D. An abstract method is one without a physical or concrete existence! Question - 11 3

Select the incorrect definition of an abstract method in Java. A. All of the methods that reside in an abstract class are by definition abstract. B. All of the methods in a Java interface are abstract methods since they cannot have an implementation. C. An abstract method cannot have an implementation until another class overrides it. D. An abstract method is one without a physical or concrete existence! Which of the following definitions is incorrect with respect to abstract classes. A. A class that extends an abstract class is a subclass, or alternatively a derived or child class. B. When extended by another class, the abstract class itself is call a superclass, or alternatively a base or parent class. C. A nonabstract subclass that extends an abstract class has to override all of its abstract methods. D. A superclass that is abstract is required to implement one or more abstract methods. Question - 12 Question - 13 Which of the following definitions is incorrect with respect to abstract classes. A. A class that extends an abstract class is a subclass, or alternatively a derived or child class. B. When extended by another class, the abstract class itself is call a superclass, or alternatively a base or parent class. C. A nonabstract subclass that extends an abstract class has to override all of its abstract methods. D. A superclass that is abstract is required to implement one or more abstract methods. Which statement is correct with respect to the diagram shown? public abstract class A { public class B public class C A. B and C are subclasses that extend A. B. A is a superclass that extends B and C. C. B and C are superclasses that extend A. D. A is a subclass that extends B and C. Question - 14 Question - 15 4

Which statement is correct with respect to the diagram shown? public abstract class A { public class B public class C A. B and C are subclasses that extend A. B. A is a superclass that extends B and C. C. B and C are superclasses that extend A. D. A is a subclass that extends B and C. Question - 16 5