SlideShare a Scribd company logo
1 of 6
Chapter 11 Inheritance and Polymorphism
1. (a) The printout is
A’s no-arg constructor is invoked
(b) The default constructor of B attempts to invoke the default of constructor of
A, but class A's default constructor is not defined.
2. All false.
(1) A subclass is an extension of a superclass and normally contains more details
information than its superclass.
(2) If a subclass’s constructor explicitly invoke a superclass’s constructor, the
superclass’s no-arg constructor is not invoked.
(3) You can only override accessible instance methods.
(4) You can only override accessible instance methods.
3. The following lines are erroneous:
{
radius = radius; // Must use this.radius = radius
}
class B extends Circle (missing extends)
{
Circle(radius); // Must use super(radius)
length = length; // Must use this.length = length
}
public double getArea()
{
return getArea()*length; // super.getArea()
}
4. Use super() or super(args). This statement must be the first in the constructor in
the subclass.
5. Use super.method() or super.method(args).
6. Method overloading defines methods of the same name in a class. Method
overriding modifies the methods that are defined in the superclasses.
7. It is method overridden.
8. It will be a syntax error.
9. It is method oveloading.
10. Yes, because these two methods are defined in the Object class; therefore, they are
available to all Java classes. The subclasses usually override these methods to
provide specific information for these methods.
The toString() method returns a string representation of the object; the equals()
method compares the contents of two objects to determine whether they are the
same.
11. B’s constructor is invoked
A’s constructor is invoked
The default constructor of Object is invoked, when new A(3)
is invoked. The Object’s constructor is invoked before any
statements in B’s constructor are executed.
12. (a)
(circle instanceof GeometricObject1) => true
(object1 instanceof GeometricObject1) => true
(circle instanceof Circle1) => true
(object1 instanceof Circle1) => false
(b)
Yes, because you can always cast from subclass to superclass.
(c)
Causing a runtime exception (ClassCastExcpetion)
13.
Is fruit instanceof Fruit true? true
Is fruit instanceof Orange true? false
Is fruit instanceof Apple true? true
Is fruit instanceof GoldDelicious true? true
Is fruit instanceof Macintosh true? false
Is orange instanceof Orange true? true
Is orange instanceof Fruit true? true
Is orange instanceof Apple true? false
Suppose the method makeApple is defined in the Apple
class. Can fruit invoke this method? Yes
Can orange invoke this method? No
Suppose the method makeOrangeJuice is defined in the
Orange class. Can orange invoke this method? Yes.
Can fruit invoke this method? No.
Is the statement Orange p = new Apple() legal? No
Is the statement Macintosh p = new Apple() legal? No
Is the statement Apple p = new Macintosh() legal? Yes
14.
Object apple = (Apple)fruit;
Causes a runtime ClassCastingException.
15. The output is false if the Circle class in (A) is
used. The Circle class has two overloaded methods:
equals(Circle circle) defined in the Circle class and
equals(Object circle) defined in the Object class,
inherited by the Circle class. At compilation time,
circle1.equals(circle2) is matched to equals(Circle
circle), because equals(Circle circle) is more specific
than equals(Object circle).
The output is true if the Circle class in (B) is used. The
Circle class overrides the equals(Object circle) method
defined in the Object class. At compilation time,
circle1.equals(circle2) is matched to equals(Circle circle)
and at runtime, the equals(Object circle) method
implemented in the Circle class is invoked.
16.
How do you create an ArrayList?
Use ArrayList list = new ArrayList();
How do you append an object to a list?
list.add(object);
How do you insert an object at the beginning of a
list?
list.add(0, object);
How do you find out the number of objects in a list?
list.size();
How do you remove a given object from a list?
list.remove(object);
How do you remove the last object from the list?
list.remove(list.size() - 1);
How do you check whether a given object is in a list?
list.contains(object);
How do you retrieve an object at a specified index
from a list?
list.get(index);
17.
Error 1:
String city = list.get(0);
Should be written as
String city = (String)list.get(0);
Error 2:
list.set(3, "Dallas");
is wrong because there is no element at index 3 in the
list.
Error 3:
list.get(3)
is wrong because there is no element at index 3 in the
list.
18. default visibility modifier.
19. protected.
20. If the question marks are replaced by blanks, can
class B be compiled? Yes.
If the question marks are replaced by private, can class B be
compiled? No.
If the question marks are replaced by protected, can class B be
compiled? Yes.
21. If the question marks are replaced by blanks, can
class B be compiled? No.
If the question marks are replaced by private, can class B be
compiled? No.
If the question marks are replaced by protected, can class B be
compiled? Yes.
22. Use the final keyword.
23. Find these terms in this chapter.
24. Indicate true or false for the following statements:
1. True.
2. False. (But yes in a subclass that extends the class where the protected
datum is defined.)
3. True.
4. A final class can have instances.
Answer: True
5. A final class can be extended.
Answer: False
6. A final method can be overridden.
Answer: False
7. You can always successfully cast a subclass to a superclass.
Answer: True
8. You can always successfully cast a superclass to a subclass.
Answer: False
25.
Matching a method signature and binding a method implementation
are two separate issues. The declared type of the reference
variable decides which method to match at compile time. The
compiler finds a matching method according to parameter type,
number of parameters, and order of the parameters at compile
time. A method may be implemented in several subclasses. The JVM
dynamically binds the implementation of the method at runtime,
decided by the actual class of the object referenced by the
variable.
26. See the text.
If the question marks are replaced by protected, can class B be
compiled? Yes.
22. Use the final keyword.
23. Find these terms in this chapter.
24. Indicate true or false for the following statements:
1. True.
2. False. (But yes in a subclass that extends the class where the protected
datum is defined.)
3. True.
4. A final class can have instances.
Answer: True
5. A final class can be extended.
Answer: False
6. A final method can be overridden.
Answer: False
7. You can always successfully cast a subclass to a superclass.
Answer: True
8. You can always successfully cast a superclass to a subclass.
Answer: False
25.
Matching a method signature and binding a method implementation
are two separate issues. The declared type of the reference
variable decides which method to match at compile time. The
compiler finds a matching method according to parameter type,
number of parameters, and order of the parameters at compile
time. A method may be implemented in several subclasses. The JVM
dynamically binds the implementation of the method at runtime,
decided by the actual class of the object referenced by the
variable.
26. See the text.

More Related Content

What's hot

Definitions of Functional Programming
Definitions of Functional ProgrammingDefinitions of Functional Programming
Definitions of Functional ProgrammingPhilip Schwarz
 
Methods common to all objects
Methods common to all objectsMethods common to all objects
Methods common to all objectsSandeep Chawla
 
Preparation Data Structures 05 chain linear_list
Preparation Data Structures 05 chain linear_listPreparation Data Structures 05 chain linear_list
Preparation Data Structures 05 chain linear_listAndres Mendez-Vazquez
 
non-strict functions, bottom and scala by-name parameters
non-strict functions, bottom and scala by-name parametersnon-strict functions, bottom and scala by-name parameters
non-strict functions, bottom and scala by-name parametersPhilip Schwarz
 
Ap Power Point Chpt8
Ap Power Point Chpt8Ap Power Point Chpt8
Ap Power Point Chpt8dplunkett
 
ICPSR - Complex Systems Models in the Social Sciences - Lab Session 2 - Profe...
ICPSR - Complex Systems Models in the Social Sciences - Lab Session 2 - Profe...ICPSR - Complex Systems Models in the Social Sciences - Lab Session 2 - Profe...
ICPSR - Complex Systems Models in the Social Sciences - Lab Session 2 - Profe...Daniel Katz
 
Monad as functor with pair of natural transformations
Monad as functor with pair of natural transformationsMonad as functor with pair of natural transformations
Monad as functor with pair of natural transformationsPhilip Schwarz
 
Writer Monad for logging execution of functions
Writer Monad for logging execution of functionsWriter Monad for logging execution of functions
Writer Monad for logging execution of functionsPhilip Schwarz
 
Monad Laws Must be Checked
Monad Laws Must be CheckedMonad Laws Must be Checked
Monad Laws Must be CheckedPhilip Schwarz
 
Functional Effects - Part 1
Functional Effects - Part 1Functional Effects - Part 1
Functional Effects - Part 1Philip Schwarz
 
Folding Unfolded - Polyglot FP for Fun and Profit - Haskell and Scala - Part 2
Folding Unfolded - Polyglot FP for Fun and Profit - Haskell and Scala - Part 2Folding Unfolded - Polyglot FP for Fun and Profit - Haskell and Scala - Part 2
Folding Unfolded - Polyglot FP for Fun and Profit - Haskell and Scala - Part 2Philip Schwarz
 
Applying Generics
Applying GenericsApplying Generics
Applying GenericsBharat17485
 
Scala 3 enum for a terser Option Monad Algebraic Data Type
Scala 3 enum for a terser Option Monad Algebraic Data TypeScala 3 enum for a terser Option Monad Algebraic Data Type
Scala 3 enum for a terser Option Monad Algebraic Data TypePhilip Schwarz
 
Folding Unfolded - Polyglot FP for Fun and Profit - Haskell and Scala - Part 4
Folding Unfolded - Polyglot FP for Fun and Profit - Haskell and Scala - Part 4Folding Unfolded - Polyglot FP for Fun and Profit - Haskell and Scala - Part 4
Folding Unfolded - Polyglot FP for Fun and Profit - Haskell and Scala - Part 4Philip Schwarz
 
‘go-to’ general-purpose sequential collections - from Java To Scala
‘go-to’ general-purpose sequential collections -from Java To Scala‘go-to’ general-purpose sequential collections -from Java To Scala
‘go-to’ general-purpose sequential collections - from Java To ScalaPhilip Schwarz
 
ES6 Template Literal & Tag Function
ES6 Template Literal & Tag FunctionES6 Template Literal & Tag Function
ES6 Template Literal & Tag FunctionJae Nam Jung
 

What's hot (20)

Definitions of Functional Programming
Definitions of Functional ProgrammingDefinitions of Functional Programming
Definitions of Functional Programming
 
Methods common to all objects
Methods common to all objectsMethods common to all objects
Methods common to all objects
 
7 algorithm
7 algorithm7 algorithm
7 algorithm
 
Preparation Data Structures 05 chain linear_list
Preparation Data Structures 05 chain linear_listPreparation Data Structures 05 chain linear_list
Preparation Data Structures 05 chain linear_list
 
non-strict functions, bottom and scala by-name parameters
non-strict functions, bottom and scala by-name parametersnon-strict functions, bottom and scala by-name parameters
non-strict functions, bottom and scala by-name parameters
 
Ap Power Point Chpt8
Ap Power Point Chpt8Ap Power Point Chpt8
Ap Power Point Chpt8
 
ICPSR - Complex Systems Models in the Social Sciences - Lab Session 2 - Profe...
ICPSR - Complex Systems Models in the Social Sciences - Lab Session 2 - Profe...ICPSR - Complex Systems Models in the Social Sciences - Lab Session 2 - Profe...
ICPSR - Complex Systems Models in the Social Sciences - Lab Session 2 - Profe...
 
Monad as functor with pair of natural transformations
Monad as functor with pair of natural transformationsMonad as functor with pair of natural transformations
Monad as functor with pair of natural transformations
 
Writer Monad for logging execution of functions
Writer Monad for logging execution of functionsWriter Monad for logging execution of functions
Writer Monad for logging execution of functions
 
Monad Laws Must be Checked
Monad Laws Must be CheckedMonad Laws Must be Checked
Monad Laws Must be Checked
 
04 a ch03_programacion
04 a ch03_programacion04 a ch03_programacion
04 a ch03_programacion
 
Functional Effects - Part 1
Functional Effects - Part 1Functional Effects - Part 1
Functional Effects - Part 1
 
Folding Unfolded - Polyglot FP for Fun and Profit - Haskell and Scala - Part 2
Folding Unfolded - Polyglot FP for Fun and Profit - Haskell and Scala - Part 2Folding Unfolded - Polyglot FP for Fun and Profit - Haskell and Scala - Part 2
Folding Unfolded - Polyglot FP for Fun and Profit - Haskell and Scala - Part 2
 
Applying Generics
Applying GenericsApplying Generics
Applying Generics
 
Scala 3 enum for a terser Option Monad Algebraic Data Type
Scala 3 enum for a terser Option Monad Algebraic Data TypeScala 3 enum for a terser Option Monad Algebraic Data Type
Scala 3 enum for a terser Option Monad Algebraic Data Type
 
Folding Unfolded - Polyglot FP for Fun and Profit - Haskell and Scala - Part 4
Folding Unfolded - Polyglot FP for Fun and Profit - Haskell and Scala - Part 4Folding Unfolded - Polyglot FP for Fun and Profit - Haskell and Scala - Part 4
Folding Unfolded - Polyglot FP for Fun and Profit - Haskell and Scala - Part 4
 
‘go-to’ general-purpose sequential collections - from Java To Scala
‘go-to’ general-purpose sequential collections -from Java To Scala‘go-to’ general-purpose sequential collections -from Java To Scala
‘go-to’ general-purpose sequential collections - from Java To Scala
 
Monad Fact #4
Monad Fact #4Monad Fact #4
Monad Fact #4
 
Java execise
Java execiseJava execise
Java execise
 
ES6 Template Literal & Tag Function
ES6 Template Literal & Tag FunctionES6 Template Literal & Tag Function
ES6 Template Literal & Tag Function
 

Viewers also liked

Daniel Witherite UT-UXO Certificate
Daniel Witherite UT-UXO CertificateDaniel Witherite UT-UXO Certificate
Daniel Witherite UT-UXO CertificateDaniel Witherite
 
Casa design 2014
Casa design 2014Casa design 2014
Casa design 2014casadesign
 
Sistemas de Información en la Empresa
Sistemas de Información en la EmpresaSistemas de Información en la Empresa
Sistemas de Información en la EmpresaEdicion Ticnews
 
Growth Hacking with Kentico
Growth Hacking with KenticoGrowth Hacking with Kentico
Growth Hacking with KenticoBrian McKeiver
 
Csc1100 lecture09 ch07_pt2
Csc1100 lecture09 ch07_pt2Csc1100 lecture09 ch07_pt2
Csc1100 lecture09 ch07_pt2IIUM
 
Mediterranean – Adriatic Underwater Cultural Heritage links
Mediterranean – Adriatic Underwater Cultural Heritage linksMediterranean – Adriatic Underwater Cultural Heritage links
Mediterranean – Adriatic Underwater Cultural Heritage linksUNESCO Venice Office
 
Oportunidad Negocio (2 )
Oportunidad Negocio (2 )Oportunidad Negocio (2 )
Oportunidad Negocio (2 )HERBALIFE
 
Startup Braga - value proposition workshop
Startup Braga - value proposition workshopStartup Braga - value proposition workshop
Startup Braga - value proposition workshopStartup Braga
 
Brochure Seminario 23 de mayo
Brochure Seminario 23 de mayoBrochure Seminario 23 de mayo
Brochure Seminario 23 de mayoEmprende Claro
 

Viewers also liked (13)

Daniel Witherite UT-UXO Certificate
Daniel Witherite UT-UXO CertificateDaniel Witherite UT-UXO Certificate
Daniel Witherite UT-UXO Certificate
 
Casa design 2014
Casa design 2014Casa design 2014
Casa design 2014
 
Sistemas de Información en la Empresa
Sistemas de Información en la EmpresaSistemas de Información en la Empresa
Sistemas de Información en la Empresa
 
Growth Hacking with Kentico
Growth Hacking with KenticoGrowth Hacking with Kentico
Growth Hacking with Kentico
 
Csc1100 lecture09 ch07_pt2
Csc1100 lecture09 ch07_pt2Csc1100 lecture09 ch07_pt2
Csc1100 lecture09 ch07_pt2
 
El informe de investigación
El informe de investigaciónEl informe de investigación
El informe de investigación
 
Mediterranean – Adriatic Underwater Cultural Heritage links
Mediterranean – Adriatic Underwater Cultural Heritage linksMediterranean – Adriatic Underwater Cultural Heritage links
Mediterranean – Adriatic Underwater Cultural Heritage links
 
YALI_Certificate (2)
YALI_Certificate (2)YALI_Certificate (2)
YALI_Certificate (2)
 
Apostila de empilhadeira rv1
Apostila de empilhadeira rv1Apostila de empilhadeira rv1
Apostila de empilhadeira rv1
 
PRIMAVERA - A Nova Fiscalidade Nacional em Angola
PRIMAVERA - A Nova Fiscalidade Nacional em AngolaPRIMAVERA - A Nova Fiscalidade Nacional em Angola
PRIMAVERA - A Nova Fiscalidade Nacional em Angola
 
Oportunidad Negocio (2 )
Oportunidad Negocio (2 )Oportunidad Negocio (2 )
Oportunidad Negocio (2 )
 
Startup Braga - value proposition workshop
Startup Braga - value proposition workshopStartup Braga - value proposition workshop
Startup Braga - value proposition workshop
 
Brochure Seminario 23 de mayo
Brochure Seminario 23 de mayoBrochure Seminario 23 de mayo
Brochure Seminario 23 de mayo
 

Similar to 11review(inheritance andpolymorphism)

Consider this code using the ArrayBag of Section 5.2 and the Locat.docx
Consider this code using the ArrayBag of Section 5.2 and the Locat.docxConsider this code using the ArrayBag of Section 5.2 and the Locat.docx
Consider this code using the ArrayBag of Section 5.2 and the Locat.docxmaxinesmith73660
 
JAVA CONCEPTS AND PRACTICES
JAVA CONCEPTS AND PRACTICESJAVA CONCEPTS AND PRACTICES
JAVA CONCEPTS AND PRACTICESNikunj Parekh
 
Prueba de conociemientos Fullsctack NET v2.docx
Prueba de conociemientos  Fullsctack NET v2.docxPrueba de conociemientos  Fullsctack NET v2.docx
Prueba de conociemientos Fullsctack NET v2.docxjairatuesta
 
Indus Valley Partner aptitude questions and answers
Indus Valley Partner aptitude questions and answersIndus Valley Partner aptitude questions and answers
Indus Valley Partner aptitude questions and answersSushant Choudhary
 
Java interview questions 2
Java interview questions 2Java interview questions 2
Java interview questions 2Sherihan Anver
 
Introduction to Ruby’s Reflection API
Introduction to Ruby’s Reflection APIIntroduction to Ruby’s Reflection API
Introduction to Ruby’s Reflection APINiranjan Sarade
 
Comp 328 final guide
Comp 328 final guideComp 328 final guide
Comp 328 final guidekrtioplal
 
Autoboxing and unboxing
Autoboxing and unboxingAutoboxing and unboxing
Autoboxing and unboxingGeetha Manohar
 
05-OOP-Abstract Classes____________.pptx
05-OOP-Abstract Classes____________.pptx05-OOP-Abstract Classes____________.pptx
05-OOP-Abstract Classes____________.pptxpaautomation11
 
06 InheritanceAndPolymorphism.ppt
06 InheritanceAndPolymorphism.ppt06 InheritanceAndPolymorphism.ppt
06 InheritanceAndPolymorphism.pptParikhitGhosh1
 
Chapter 8 Inheritance
Chapter 8 InheritanceChapter 8 Inheritance
Chapter 8 InheritanceOUM SAOKOSAL
 
Core java by a introduction sandesh sharma
Core java by a introduction sandesh sharmaCore java by a introduction sandesh sharma
Core java by a introduction sandesh sharmaSandesh Sharma
 
Question 1 The syntax for accessing a class (struct) member .docx
Question 1 The syntax for accessing a class (struct) member .docxQuestion 1 The syntax for accessing a class (struct) member .docx
Question 1 The syntax for accessing a class (struct) member .docxmakdul
 

Similar to 11review(inheritance andpolymorphism) (20)

Collections
CollectionsCollections
Collections
 
CORE JAVA
CORE JAVACORE JAVA
CORE JAVA
 
Consider this code using the ArrayBag of Section 5.2 and the Locat.docx
Consider this code using the ArrayBag of Section 5.2 and the Locat.docxConsider this code using the ArrayBag of Section 5.2 and the Locat.docx
Consider this code using the ArrayBag of Section 5.2 and the Locat.docx
 
JAVA CONCEPTS AND PRACTICES
JAVA CONCEPTS AND PRACTICESJAVA CONCEPTS AND PRACTICES
JAVA CONCEPTS AND PRACTICES
 
Jist of Java
Jist of JavaJist of Java
Jist of Java
 
Prueba de conociemientos Fullsctack NET v2.docx
Prueba de conociemientos  Fullsctack NET v2.docxPrueba de conociemientos  Fullsctack NET v2.docx
Prueba de conociemientos Fullsctack NET v2.docx
 
Indus Valley Partner aptitude questions and answers
Indus Valley Partner aptitude questions and answersIndus Valley Partner aptitude questions and answers
Indus Valley Partner aptitude questions and answers
 
Java interview questions 2
Java interview questions 2Java interview questions 2
Java interview questions 2
 
Introduction to Ruby’s Reflection API
Introduction to Ruby’s Reflection APIIntroduction to Ruby’s Reflection API
Introduction to Ruby’s Reflection API
 
Inheritance
InheritanceInheritance
Inheritance
 
Comp 328 final guide
Comp 328 final guideComp 328 final guide
Comp 328 final guide
 
Autoboxing and unboxing
Autoboxing and unboxingAutoboxing and unboxing
Autoboxing and unboxing
 
Java collections notes
Java collections notesJava collections notes
Java collections notes
 
05-OOP-Abstract Classes____________.pptx
05-OOP-Abstract Classes____________.pptx05-OOP-Abstract Classes____________.pptx
05-OOP-Abstract Classes____________.pptx
 
06 InheritanceAndPolymorphism.ppt
06 InheritanceAndPolymorphism.ppt06 InheritanceAndPolymorphism.ppt
06 InheritanceAndPolymorphism.ppt
 
Java interview questions
Java interview questionsJava interview questions
Java interview questions
 
Chapter 8 Inheritance
Chapter 8 InheritanceChapter 8 Inheritance
Chapter 8 Inheritance
 
Core java by a introduction sandesh sharma
Core java by a introduction sandesh sharmaCore java by a introduction sandesh sharma
Core java by a introduction sandesh sharma
 
Design pattern
Design patternDesign pattern
Design pattern
 
Question 1 The syntax for accessing a class (struct) member .docx
Question 1 The syntax for accessing a class (struct) member .docxQuestion 1 The syntax for accessing a class (struct) member .docx
Question 1 The syntax for accessing a class (struct) member .docx
 

More from IIUM

How to use_000webhost
How to use_000webhostHow to use_000webhost
How to use_000webhostIIUM
 
Chapter 2
Chapter 2Chapter 2
Chapter 2IIUM
 
Chapter 1
Chapter 1Chapter 1
Chapter 1IIUM
 
Kreydle internship-multimedia
Kreydle internship-multimediaKreydle internship-multimedia
Kreydle internship-multimediaIIUM
 
03phpbldgblock
03phpbldgblock03phpbldgblock
03phpbldgblockIIUM
 
Chap2 practice key
Chap2 practice keyChap2 practice key
Chap2 practice keyIIUM
 
Group p1
Group p1Group p1
Group p1IIUM
 
Tutorial import n auto pilot blogspot friendly seo
Tutorial import n auto pilot blogspot friendly seoTutorial import n auto pilot blogspot friendly seo
Tutorial import n auto pilot blogspot friendly seoIIUM
 
Visual sceneperception encycloperception-sage-oliva2009
Visual sceneperception encycloperception-sage-oliva2009Visual sceneperception encycloperception-sage-oliva2009
Visual sceneperception encycloperception-sage-oliva2009IIUM
 
03 the htm_lforms
03 the htm_lforms03 the htm_lforms
03 the htm_lformsIIUM
 
Exercise on algo analysis answer
Exercise on algo analysis   answerExercise on algo analysis   answer
Exercise on algo analysis answerIIUM
 
Redo midterm
Redo midtermRedo midterm
Redo midtermIIUM
 
Heaps
HeapsHeaps
HeapsIIUM
 
Report format
Report formatReport format
Report formatIIUM
 
Edpuzzle guidelines
Edpuzzle guidelinesEdpuzzle guidelines
Edpuzzle guidelinesIIUM
 
Final Exam Paper
Final Exam PaperFinal Exam Paper
Final Exam PaperIIUM
 
Final Exam Paper
Final Exam PaperFinal Exam Paper
Final Exam PaperIIUM
 
Group assignment 1 s21516
Group assignment 1 s21516Group assignment 1 s21516
Group assignment 1 s21516IIUM
 
Avl tree-rotations
Avl tree-rotationsAvl tree-rotations
Avl tree-rotationsIIUM
 
Week12 graph
Week12   graph Week12   graph
Week12 graph IIUM
 

More from IIUM (20)

How to use_000webhost
How to use_000webhostHow to use_000webhost
How to use_000webhost
 
Chapter 2
Chapter 2Chapter 2
Chapter 2
 
Chapter 1
Chapter 1Chapter 1
Chapter 1
 
Kreydle internship-multimedia
Kreydle internship-multimediaKreydle internship-multimedia
Kreydle internship-multimedia
 
03phpbldgblock
03phpbldgblock03phpbldgblock
03phpbldgblock
 
Chap2 practice key
Chap2 practice keyChap2 practice key
Chap2 practice key
 
Group p1
Group p1Group p1
Group p1
 
Tutorial import n auto pilot blogspot friendly seo
Tutorial import n auto pilot blogspot friendly seoTutorial import n auto pilot blogspot friendly seo
Tutorial import n auto pilot blogspot friendly seo
 
Visual sceneperception encycloperception-sage-oliva2009
Visual sceneperception encycloperception-sage-oliva2009Visual sceneperception encycloperception-sage-oliva2009
Visual sceneperception encycloperception-sage-oliva2009
 
03 the htm_lforms
03 the htm_lforms03 the htm_lforms
03 the htm_lforms
 
Exercise on algo analysis answer
Exercise on algo analysis   answerExercise on algo analysis   answer
Exercise on algo analysis answer
 
Redo midterm
Redo midtermRedo midterm
Redo midterm
 
Heaps
HeapsHeaps
Heaps
 
Report format
Report formatReport format
Report format
 
Edpuzzle guidelines
Edpuzzle guidelinesEdpuzzle guidelines
Edpuzzle guidelines
 
Final Exam Paper
Final Exam PaperFinal Exam Paper
Final Exam Paper
 
Final Exam Paper
Final Exam PaperFinal Exam Paper
Final Exam Paper
 
Group assignment 1 s21516
Group assignment 1 s21516Group assignment 1 s21516
Group assignment 1 s21516
 
Avl tree-rotations
Avl tree-rotationsAvl tree-rotations
Avl tree-rotations
 
Week12 graph
Week12   graph Week12   graph
Week12 graph
 

Recently uploaded

Call Girl Coimbatore Prisha☎️ 8250192130 Independent Escort Service Coimbatore
Call Girl Coimbatore Prisha☎️  8250192130 Independent Escort Service CoimbatoreCall Girl Coimbatore Prisha☎️  8250192130 Independent Escort Service Coimbatore
Call Girl Coimbatore Prisha☎️ 8250192130 Independent Escort Service Coimbatorenarwatsonia7
 
Call Girls Service Chennai Jiya 7001305949 Independent Escort Service Chennai
Call Girls Service Chennai Jiya 7001305949 Independent Escort Service ChennaiCall Girls Service Chennai Jiya 7001305949 Independent Escort Service Chennai
Call Girls Service Chennai Jiya 7001305949 Independent Escort Service ChennaiNehru place Escorts
 
Call Girl Number in Panvel Mumbai📲 9833363713 💞 Full Night Enjoy
Call Girl Number in Panvel Mumbai📲 9833363713 💞 Full Night EnjoyCall Girl Number in Panvel Mumbai📲 9833363713 💞 Full Night Enjoy
Call Girl Number in Panvel Mumbai📲 9833363713 💞 Full Night Enjoybabeytanya
 
VIP Call Girls Pune Vani 9907093804 Short 1500 Night 6000 Best call girls Ser...
VIP Call Girls Pune Vani 9907093804 Short 1500 Night 6000 Best call girls Ser...VIP Call Girls Pune Vani 9907093804 Short 1500 Night 6000 Best call girls Ser...
VIP Call Girls Pune Vani 9907093804 Short 1500 Night 6000 Best call girls Ser...Miss joya
 
High Profile Call Girls Coimbatore Saanvi☎️ 8250192130 Independent Escort Se...
High Profile Call Girls Coimbatore Saanvi☎️  8250192130 Independent Escort Se...High Profile Call Girls Coimbatore Saanvi☎️  8250192130 Independent Escort Se...
High Profile Call Girls Coimbatore Saanvi☎️ 8250192130 Independent Escort Se...narwatsonia7
 
Call Girls Service In Shyam Nagar Whatsapp 8445551418 Independent Escort Service
Call Girls Service In Shyam Nagar Whatsapp 8445551418 Independent Escort ServiceCall Girls Service In Shyam Nagar Whatsapp 8445551418 Independent Escort Service
Call Girls Service In Shyam Nagar Whatsapp 8445551418 Independent Escort Serviceparulsinha
 
Call Girls Service Pune Vaishnavi 9907093804 Short 1500 Night 6000 Best call ...
Call Girls Service Pune Vaishnavi 9907093804 Short 1500 Night 6000 Best call ...Call Girls Service Pune Vaishnavi 9907093804 Short 1500 Night 6000 Best call ...
Call Girls Service Pune Vaishnavi 9907093804 Short 1500 Night 6000 Best call ...Miss joya
 
Russian Call Girls in Bangalore Manisha 7001305949 Independent Escort Service...
Russian Call Girls in Bangalore Manisha 7001305949 Independent Escort Service...Russian Call Girls in Bangalore Manisha 7001305949 Independent Escort Service...
Russian Call Girls in Bangalore Manisha 7001305949 Independent Escort Service...narwatsonia7
 
Call Girls In Andheri East Call 9920874524 Book Hot And Sexy Girls
Call Girls In Andheri East Call 9920874524 Book Hot And Sexy GirlsCall Girls In Andheri East Call 9920874524 Book Hot And Sexy Girls
Call Girls In Andheri East Call 9920874524 Book Hot And Sexy Girlsnehamumbai
 
Call Girls Colaba Mumbai ❤️ 9920874524 👈 Cash on Delivery
Call Girls Colaba Mumbai ❤️ 9920874524 👈 Cash on DeliveryCall Girls Colaba Mumbai ❤️ 9920874524 👈 Cash on Delivery
Call Girls Colaba Mumbai ❤️ 9920874524 👈 Cash on Deliverynehamumbai
 
Best Rate (Hyderabad) Call Girls Jahanuma ⟟ 8250192130 ⟟ High Class Call Girl...
Best Rate (Hyderabad) Call Girls Jahanuma ⟟ 8250192130 ⟟ High Class Call Girl...Best Rate (Hyderabad) Call Girls Jahanuma ⟟ 8250192130 ⟟ High Class Call Girl...
Best Rate (Hyderabad) Call Girls Jahanuma ⟟ 8250192130 ⟟ High Class Call Girl...astropune
 
College Call Girls Pune Mira 9907093804 Short 1500 Night 6000 Best call girls...
College Call Girls Pune Mira 9907093804 Short 1500 Night 6000 Best call girls...College Call Girls Pune Mira 9907093804 Short 1500 Night 6000 Best call girls...
College Call Girls Pune Mira 9907093804 Short 1500 Night 6000 Best call girls...Miss joya
 
Bangalore Call Girls Nelamangala Number 7001035870 Meetin With Bangalore Esc...
Bangalore Call Girls Nelamangala Number 7001035870  Meetin With Bangalore Esc...Bangalore Call Girls Nelamangala Number 7001035870  Meetin With Bangalore Esc...
Bangalore Call Girls Nelamangala Number 7001035870 Meetin With Bangalore Esc...narwatsonia7
 
VIP Call Girls Indore Kirti 💚😋 9256729539 🚀 Indore Escorts
VIP Call Girls Indore Kirti 💚😋  9256729539 🚀 Indore EscortsVIP Call Girls Indore Kirti 💚😋  9256729539 🚀 Indore Escorts
VIP Call Girls Indore Kirti 💚😋 9256729539 🚀 Indore Escortsaditipandeya
 
Low Rate Call Girls Pune Esha 9907093804 Short 1500 Night 6000 Best call girl...
Low Rate Call Girls Pune Esha 9907093804 Short 1500 Night 6000 Best call girl...Low Rate Call Girls Pune Esha 9907093804 Short 1500 Night 6000 Best call girl...
Low Rate Call Girls Pune Esha 9907093804 Short 1500 Night 6000 Best call girl...Miss joya
 
Bangalore Call Girls Hebbal Kempapura Number 7001035870 Meetin With Bangalor...
Bangalore Call Girls Hebbal Kempapura Number 7001035870  Meetin With Bangalor...Bangalore Call Girls Hebbal Kempapura Number 7001035870  Meetin With Bangalor...
Bangalore Call Girls Hebbal Kempapura Number 7001035870 Meetin With Bangalor...narwatsonia7
 
♛VVIP Hyderabad Call Girls Chintalkunta🖕7001035870🖕Riya Kappor Top Call Girl ...
♛VVIP Hyderabad Call Girls Chintalkunta🖕7001035870🖕Riya Kappor Top Call Girl ...♛VVIP Hyderabad Call Girls Chintalkunta🖕7001035870🖕Riya Kappor Top Call Girl ...
♛VVIP Hyderabad Call Girls Chintalkunta🖕7001035870🖕Riya Kappor Top Call Girl ...astropune
 
Artifacts in Nuclear Medicine with Identifying and resolving artifacts.
Artifacts in Nuclear Medicine with Identifying and resolving artifacts.Artifacts in Nuclear Medicine with Identifying and resolving artifacts.
Artifacts in Nuclear Medicine with Identifying and resolving artifacts.MiadAlsulami
 
VIP Call Girls Tirunelveli Aaradhya 8250192130 Independent Escort Service Tir...
VIP Call Girls Tirunelveli Aaradhya 8250192130 Independent Escort Service Tir...VIP Call Girls Tirunelveli Aaradhya 8250192130 Independent Escort Service Tir...
VIP Call Girls Tirunelveli Aaradhya 8250192130 Independent Escort Service Tir...narwatsonia7
 

Recently uploaded (20)

Call Girl Coimbatore Prisha☎️ 8250192130 Independent Escort Service Coimbatore
Call Girl Coimbatore Prisha☎️  8250192130 Independent Escort Service CoimbatoreCall Girl Coimbatore Prisha☎️  8250192130 Independent Escort Service Coimbatore
Call Girl Coimbatore Prisha☎️ 8250192130 Independent Escort Service Coimbatore
 
sauth delhi call girls in Bhajanpura 🔝 9953056974 🔝 escort Service
sauth delhi call girls in Bhajanpura 🔝 9953056974 🔝 escort Servicesauth delhi call girls in Bhajanpura 🔝 9953056974 🔝 escort Service
sauth delhi call girls in Bhajanpura 🔝 9953056974 🔝 escort Service
 
Call Girls Service Chennai Jiya 7001305949 Independent Escort Service Chennai
Call Girls Service Chennai Jiya 7001305949 Independent Escort Service ChennaiCall Girls Service Chennai Jiya 7001305949 Independent Escort Service Chennai
Call Girls Service Chennai Jiya 7001305949 Independent Escort Service Chennai
 
Call Girl Number in Panvel Mumbai📲 9833363713 💞 Full Night Enjoy
Call Girl Number in Panvel Mumbai📲 9833363713 💞 Full Night EnjoyCall Girl Number in Panvel Mumbai📲 9833363713 💞 Full Night Enjoy
Call Girl Number in Panvel Mumbai📲 9833363713 💞 Full Night Enjoy
 
VIP Call Girls Pune Vani 9907093804 Short 1500 Night 6000 Best call girls Ser...
VIP Call Girls Pune Vani 9907093804 Short 1500 Night 6000 Best call girls Ser...VIP Call Girls Pune Vani 9907093804 Short 1500 Night 6000 Best call girls Ser...
VIP Call Girls Pune Vani 9907093804 Short 1500 Night 6000 Best call girls Ser...
 
High Profile Call Girls Coimbatore Saanvi☎️ 8250192130 Independent Escort Se...
High Profile Call Girls Coimbatore Saanvi☎️  8250192130 Independent Escort Se...High Profile Call Girls Coimbatore Saanvi☎️  8250192130 Independent Escort Se...
High Profile Call Girls Coimbatore Saanvi☎️ 8250192130 Independent Escort Se...
 
Call Girls Service In Shyam Nagar Whatsapp 8445551418 Independent Escort Service
Call Girls Service In Shyam Nagar Whatsapp 8445551418 Independent Escort ServiceCall Girls Service In Shyam Nagar Whatsapp 8445551418 Independent Escort Service
Call Girls Service In Shyam Nagar Whatsapp 8445551418 Independent Escort Service
 
Call Girls Service Pune Vaishnavi 9907093804 Short 1500 Night 6000 Best call ...
Call Girls Service Pune Vaishnavi 9907093804 Short 1500 Night 6000 Best call ...Call Girls Service Pune Vaishnavi 9907093804 Short 1500 Night 6000 Best call ...
Call Girls Service Pune Vaishnavi 9907093804 Short 1500 Night 6000 Best call ...
 
Russian Call Girls in Bangalore Manisha 7001305949 Independent Escort Service...
Russian Call Girls in Bangalore Manisha 7001305949 Independent Escort Service...Russian Call Girls in Bangalore Manisha 7001305949 Independent Escort Service...
Russian Call Girls in Bangalore Manisha 7001305949 Independent Escort Service...
 
Call Girls In Andheri East Call 9920874524 Book Hot And Sexy Girls
Call Girls In Andheri East Call 9920874524 Book Hot And Sexy GirlsCall Girls In Andheri East Call 9920874524 Book Hot And Sexy Girls
Call Girls In Andheri East Call 9920874524 Book Hot And Sexy Girls
 
Call Girls Colaba Mumbai ❤️ 9920874524 👈 Cash on Delivery
Call Girls Colaba Mumbai ❤️ 9920874524 👈 Cash on DeliveryCall Girls Colaba Mumbai ❤️ 9920874524 👈 Cash on Delivery
Call Girls Colaba Mumbai ❤️ 9920874524 👈 Cash on Delivery
 
Best Rate (Hyderabad) Call Girls Jahanuma ⟟ 8250192130 ⟟ High Class Call Girl...
Best Rate (Hyderabad) Call Girls Jahanuma ⟟ 8250192130 ⟟ High Class Call Girl...Best Rate (Hyderabad) Call Girls Jahanuma ⟟ 8250192130 ⟟ High Class Call Girl...
Best Rate (Hyderabad) Call Girls Jahanuma ⟟ 8250192130 ⟟ High Class Call Girl...
 
College Call Girls Pune Mira 9907093804 Short 1500 Night 6000 Best call girls...
College Call Girls Pune Mira 9907093804 Short 1500 Night 6000 Best call girls...College Call Girls Pune Mira 9907093804 Short 1500 Night 6000 Best call girls...
College Call Girls Pune Mira 9907093804 Short 1500 Night 6000 Best call girls...
 
Bangalore Call Girls Nelamangala Number 7001035870 Meetin With Bangalore Esc...
Bangalore Call Girls Nelamangala Number 7001035870  Meetin With Bangalore Esc...Bangalore Call Girls Nelamangala Number 7001035870  Meetin With Bangalore Esc...
Bangalore Call Girls Nelamangala Number 7001035870 Meetin With Bangalore Esc...
 
VIP Call Girls Indore Kirti 💚😋 9256729539 🚀 Indore Escorts
VIP Call Girls Indore Kirti 💚😋  9256729539 🚀 Indore EscortsVIP Call Girls Indore Kirti 💚😋  9256729539 🚀 Indore Escorts
VIP Call Girls Indore Kirti 💚😋 9256729539 🚀 Indore Escorts
 
Low Rate Call Girls Pune Esha 9907093804 Short 1500 Night 6000 Best call girl...
Low Rate Call Girls Pune Esha 9907093804 Short 1500 Night 6000 Best call girl...Low Rate Call Girls Pune Esha 9907093804 Short 1500 Night 6000 Best call girl...
Low Rate Call Girls Pune Esha 9907093804 Short 1500 Night 6000 Best call girl...
 
Bangalore Call Girls Hebbal Kempapura Number 7001035870 Meetin With Bangalor...
Bangalore Call Girls Hebbal Kempapura Number 7001035870  Meetin With Bangalor...Bangalore Call Girls Hebbal Kempapura Number 7001035870  Meetin With Bangalor...
Bangalore Call Girls Hebbal Kempapura Number 7001035870 Meetin With Bangalor...
 
♛VVIP Hyderabad Call Girls Chintalkunta🖕7001035870🖕Riya Kappor Top Call Girl ...
♛VVIP Hyderabad Call Girls Chintalkunta🖕7001035870🖕Riya Kappor Top Call Girl ...♛VVIP Hyderabad Call Girls Chintalkunta🖕7001035870🖕Riya Kappor Top Call Girl ...
♛VVIP Hyderabad Call Girls Chintalkunta🖕7001035870🖕Riya Kappor Top Call Girl ...
 
Artifacts in Nuclear Medicine with Identifying and resolving artifacts.
Artifacts in Nuclear Medicine with Identifying and resolving artifacts.Artifacts in Nuclear Medicine with Identifying and resolving artifacts.
Artifacts in Nuclear Medicine with Identifying and resolving artifacts.
 
VIP Call Girls Tirunelveli Aaradhya 8250192130 Independent Escort Service Tir...
VIP Call Girls Tirunelveli Aaradhya 8250192130 Independent Escort Service Tir...VIP Call Girls Tirunelveli Aaradhya 8250192130 Independent Escort Service Tir...
VIP Call Girls Tirunelveli Aaradhya 8250192130 Independent Escort Service Tir...
 

11review(inheritance andpolymorphism)

  • 1. Chapter 11 Inheritance and Polymorphism 1. (a) The printout is A’s no-arg constructor is invoked (b) The default constructor of B attempts to invoke the default of constructor of A, but class A's default constructor is not defined. 2. All false. (1) A subclass is an extension of a superclass and normally contains more details information than its superclass. (2) If a subclass’s constructor explicitly invoke a superclass’s constructor, the superclass’s no-arg constructor is not invoked. (3) You can only override accessible instance methods. (4) You can only override accessible instance methods. 3. The following lines are erroneous: { radius = radius; // Must use this.radius = radius } class B extends Circle (missing extends) { Circle(radius); // Must use super(radius) length = length; // Must use this.length = length } public double getArea() { return getArea()*length; // super.getArea() } 4. Use super() or super(args). This statement must be the first in the constructor in the subclass. 5. Use super.method() or super.method(args). 6. Method overloading defines methods of the same name in a class. Method overriding modifies the methods that are defined in the superclasses. 7. It is method overridden. 8. It will be a syntax error.
  • 2. 9. It is method oveloading. 10. Yes, because these two methods are defined in the Object class; therefore, they are available to all Java classes. The subclasses usually override these methods to provide specific information for these methods. The toString() method returns a string representation of the object; the equals() method compares the contents of two objects to determine whether they are the same. 11. B’s constructor is invoked A’s constructor is invoked The default constructor of Object is invoked, when new A(3) is invoked. The Object’s constructor is invoked before any statements in B’s constructor are executed. 12. (a) (circle instanceof GeometricObject1) => true (object1 instanceof GeometricObject1) => true (circle instanceof Circle1) => true (object1 instanceof Circle1) => false (b) Yes, because you can always cast from subclass to superclass. (c) Causing a runtime exception (ClassCastExcpetion) 13. Is fruit instanceof Fruit true? true Is fruit instanceof Orange true? false Is fruit instanceof Apple true? true Is fruit instanceof GoldDelicious true? true Is fruit instanceof Macintosh true? false Is orange instanceof Orange true? true Is orange instanceof Fruit true? true Is orange instanceof Apple true? false Suppose the method makeApple is defined in the Apple class. Can fruit invoke this method? Yes
  • 3. Can orange invoke this method? No Suppose the method makeOrangeJuice is defined in the Orange class. Can orange invoke this method? Yes. Can fruit invoke this method? No. Is the statement Orange p = new Apple() legal? No Is the statement Macintosh p = new Apple() legal? No Is the statement Apple p = new Macintosh() legal? Yes 14. Object apple = (Apple)fruit; Causes a runtime ClassCastingException. 15. The output is false if the Circle class in (A) is used. The Circle class has two overloaded methods: equals(Circle circle) defined in the Circle class and equals(Object circle) defined in the Object class, inherited by the Circle class. At compilation time, circle1.equals(circle2) is matched to equals(Circle circle), because equals(Circle circle) is more specific than equals(Object circle). The output is true if the Circle class in (B) is used. The Circle class overrides the equals(Object circle) method defined in the Object class. At compilation time, circle1.equals(circle2) is matched to equals(Circle circle) and at runtime, the equals(Object circle) method implemented in the Circle class is invoked. 16. How do you create an ArrayList? Use ArrayList list = new ArrayList(); How do you append an object to a list? list.add(object); How do you insert an object at the beginning of a list? list.add(0, object); How do you find out the number of objects in a list? list.size();
  • 4. How do you remove a given object from a list? list.remove(object); How do you remove the last object from the list? list.remove(list.size() - 1); How do you check whether a given object is in a list? list.contains(object); How do you retrieve an object at a specified index from a list? list.get(index); 17. Error 1: String city = list.get(0); Should be written as String city = (String)list.get(0); Error 2: list.set(3, "Dallas"); is wrong because there is no element at index 3 in the list. Error 3: list.get(3) is wrong because there is no element at index 3 in the list. 18. default visibility modifier. 19. protected. 20. If the question marks are replaced by blanks, can class B be compiled? Yes. If the question marks are replaced by private, can class B be compiled? No. If the question marks are replaced by protected, can class B be compiled? Yes. 21. If the question marks are replaced by blanks, can class B be compiled? No. If the question marks are replaced by private, can class B be compiled? No.
  • 5. If the question marks are replaced by protected, can class B be compiled? Yes. 22. Use the final keyword. 23. Find these terms in this chapter. 24. Indicate true or false for the following statements: 1. True. 2. False. (But yes in a subclass that extends the class where the protected datum is defined.) 3. True. 4. A final class can have instances. Answer: True 5. A final class can be extended. Answer: False 6. A final method can be overridden. Answer: False 7. You can always successfully cast a subclass to a superclass. Answer: True 8. You can always successfully cast a superclass to a subclass. Answer: False 25. Matching a method signature and binding a method implementation are two separate issues. The declared type of the reference variable decides which method to match at compile time. The compiler finds a matching method according to parameter type, number of parameters, and order of the parameters at compile time. A method may be implemented in several subclasses. The JVM dynamically binds the implementation of the method at runtime, decided by the actual class of the object referenced by the variable. 26. See the text.
  • 6. If the question marks are replaced by protected, can class B be compiled? Yes. 22. Use the final keyword. 23. Find these terms in this chapter. 24. Indicate true or false for the following statements: 1. True. 2. False. (But yes in a subclass that extends the class where the protected datum is defined.) 3. True. 4. A final class can have instances. Answer: True 5. A final class can be extended. Answer: False 6. A final method can be overridden. Answer: False 7. You can always successfully cast a subclass to a superclass. Answer: True 8. You can always successfully cast a superclass to a subclass. Answer: False 25. Matching a method signature and binding a method implementation are two separate issues. The declared type of the reference variable decides which method to match at compile time. The compiler finds a matching method according to parameter type, number of parameters, and order of the parameters at compile time. A method may be implemented in several subclasses. The JVM dynamically binds the implementation of the method at runtime, decided by the actual class of the object referenced by the variable. 26. See the text.