SlideShare uma empresa Scribd logo
1 de 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.

Mais conteúdo relacionado

Mais procurados

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
 

Mais procurados (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
 

Destaque

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
 

Destaque (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
 

Semelhante a 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
 

Semelhante a 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
 

Mais de 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
 

Mais de 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
 

Último

(👑VVIP ISHAAN ) Russian Call Girls Service Navi Mumbai🖕9920874524🖕Independent...
(👑VVIP ISHAAN ) Russian Call Girls Service Navi Mumbai🖕9920874524🖕Independent...(👑VVIP ISHAAN ) Russian Call Girls Service Navi Mumbai🖕9920874524🖕Independent...
(👑VVIP ISHAAN ) Russian Call Girls Service Navi Mumbai🖕9920874524🖕Independent...Taniya Sharma
 
Call Girls Gwalior Just Call 8617370543 Top Class Call Girl Service Available
Call Girls Gwalior Just Call 8617370543 Top Class Call Girl Service AvailableCall Girls Gwalior Just Call 8617370543 Top Class Call Girl Service Available
Call Girls Gwalior Just Call 8617370543 Top Class Call Girl Service AvailableDipal Arora
 
Premium Call Girls Cottonpet Whatsapp 7001035870 Independent Escort Service
Premium Call Girls Cottonpet Whatsapp 7001035870 Independent Escort ServicePremium Call Girls Cottonpet Whatsapp 7001035870 Independent Escort Service
Premium Call Girls Cottonpet Whatsapp 7001035870 Independent Escort Servicevidya singh
 
Call Girls Aurangabad Just Call 9907093804 Top Class Call Girl Service Available
Call Girls Aurangabad Just Call 9907093804 Top Class Call Girl Service AvailableCall Girls Aurangabad Just Call 9907093804 Top Class Call Girl Service Available
Call Girls Aurangabad Just Call 9907093804 Top Class Call Girl Service AvailableDipal Arora
 
Call Girls Kochi Just Call 9907093804 Top Class Call Girl Service Available
Call Girls Kochi Just Call 9907093804 Top Class Call Girl Service AvailableCall Girls Kochi Just Call 9907093804 Top Class Call Girl Service Available
Call Girls Kochi Just Call 9907093804 Top Class Call Girl Service AvailableDipal Arora
 
Chandrapur Call girls 8617370543 Provides all area service COD available
Chandrapur Call girls 8617370543 Provides all area service COD availableChandrapur Call girls 8617370543 Provides all area service COD available
Chandrapur Call girls 8617370543 Provides all area service COD availableDipal Arora
 
Call Girls Nagpur Just Call 9907093804 Top Class Call Girl Service Available
Call Girls Nagpur Just Call 9907093804 Top Class Call Girl Service AvailableCall Girls Nagpur Just Call 9907093804 Top Class Call Girl Service Available
Call Girls Nagpur Just Call 9907093804 Top Class Call Girl Service AvailableDipal Arora
 
Russian Call Girls in Jaipur Riya WhatsApp ❤8445551418 VIP Call Girls Jaipur
Russian Call Girls in Jaipur Riya WhatsApp ❤8445551418 VIP Call Girls JaipurRussian Call Girls in Jaipur Riya WhatsApp ❤8445551418 VIP Call Girls Jaipur
Russian Call Girls in Jaipur Riya WhatsApp ❤8445551418 VIP Call Girls Jaipurparulsinha
 
Call Girls Ooty Just Call 9907093804 Top Class Call Girl Service Available
Call Girls Ooty Just Call 9907093804 Top Class Call Girl Service AvailableCall Girls Ooty Just Call 9907093804 Top Class Call Girl Service Available
Call Girls Ooty Just Call 9907093804 Top Class Call Girl Service AvailableDipal Arora
 
Lucknow Call girls - 8800925952 - 24x7 service with hotel room
Lucknow Call girls - 8800925952 - 24x7 service with hotel roomLucknow Call girls - 8800925952 - 24x7 service with hotel room
Lucknow Call girls - 8800925952 - 24x7 service with hotel roomdiscovermytutordmt
 
Top Quality Call Girl Service Kalyanpur 6378878445 Available Call Girls Any Time
Top Quality Call Girl Service Kalyanpur 6378878445 Available Call Girls Any TimeTop Quality Call Girl Service Kalyanpur 6378878445 Available Call Girls Any Time
Top Quality Call Girl Service Kalyanpur 6378878445 Available Call Girls Any TimeCall Girls Delhi
 
Call Girls Dehradun Just Call 9907093804 Top Class Call Girl Service Available
Call Girls Dehradun Just Call 9907093804 Top Class Call Girl Service AvailableCall Girls Dehradun Just Call 9907093804 Top Class Call Girl Service Available
Call Girls Dehradun Just Call 9907093804 Top Class Call Girl Service AvailableDipal Arora
 
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
 
♛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
 
Call Girls Horamavu WhatsApp Number 7001035870 Meeting With Bangalore Escorts
Call Girls Horamavu WhatsApp Number 7001035870 Meeting With Bangalore EscortsCall Girls Horamavu WhatsApp Number 7001035870 Meeting With Bangalore Escorts
Call Girls Horamavu WhatsApp Number 7001035870 Meeting With Bangalore Escortsvidya singh
 
Call Girls Faridabad Just Call 9907093804 Top Class Call Girl Service Available
Call Girls Faridabad Just Call 9907093804 Top Class Call Girl Service AvailableCall Girls Faridabad Just Call 9907093804 Top Class Call Girl Service Available
Call Girls Faridabad Just Call 9907093804 Top Class Call Girl Service AvailableDipal Arora
 
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
 
Call Girls Visakhapatnam Just Call 9907093804 Top Class Call Girl Service Ava...
Call Girls Visakhapatnam Just Call 9907093804 Top Class Call Girl Service Ava...Call Girls Visakhapatnam Just Call 9907093804 Top Class Call Girl Service Ava...
Call Girls Visakhapatnam Just Call 9907093804 Top Class Call Girl Service Ava...Dipal Arora
 
College Call Girls in Haridwar 9667172968 Short 4000 Night 10000 Best call gi...
College Call Girls in Haridwar 9667172968 Short 4000 Night 10000 Best call gi...College Call Girls in Haridwar 9667172968 Short 4000 Night 10000 Best call gi...
College Call Girls in Haridwar 9667172968 Short 4000 Night 10000 Best call gi...perfect solution
 
All Time Service Available Call Girls Marine Drive 📳 9820252231 For 18+ VIP C...
All Time Service Available Call Girls Marine Drive 📳 9820252231 For 18+ VIP C...All Time Service Available Call Girls Marine Drive 📳 9820252231 For 18+ VIP C...
All Time Service Available Call Girls Marine Drive 📳 9820252231 For 18+ VIP C...Arohi Goyal
 

Último (20)

(👑VVIP ISHAAN ) Russian Call Girls Service Navi Mumbai🖕9920874524🖕Independent...
(👑VVIP ISHAAN ) Russian Call Girls Service Navi Mumbai🖕9920874524🖕Independent...(👑VVIP ISHAAN ) Russian Call Girls Service Navi Mumbai🖕9920874524🖕Independent...
(👑VVIP ISHAAN ) Russian Call Girls Service Navi Mumbai🖕9920874524🖕Independent...
 
Call Girls Gwalior Just Call 8617370543 Top Class Call Girl Service Available
Call Girls Gwalior Just Call 8617370543 Top Class Call Girl Service AvailableCall Girls Gwalior Just Call 8617370543 Top Class Call Girl Service Available
Call Girls Gwalior Just Call 8617370543 Top Class Call Girl Service Available
 
Premium Call Girls Cottonpet Whatsapp 7001035870 Independent Escort Service
Premium Call Girls Cottonpet Whatsapp 7001035870 Independent Escort ServicePremium Call Girls Cottonpet Whatsapp 7001035870 Independent Escort Service
Premium Call Girls Cottonpet Whatsapp 7001035870 Independent Escort Service
 
Call Girls Aurangabad Just Call 9907093804 Top Class Call Girl Service Available
Call Girls Aurangabad Just Call 9907093804 Top Class Call Girl Service AvailableCall Girls Aurangabad Just Call 9907093804 Top Class Call Girl Service Available
Call Girls Aurangabad Just Call 9907093804 Top Class Call Girl Service Available
 
Call Girls Kochi Just Call 9907093804 Top Class Call Girl Service Available
Call Girls Kochi Just Call 9907093804 Top Class Call Girl Service AvailableCall Girls Kochi Just Call 9907093804 Top Class Call Girl Service Available
Call Girls Kochi Just Call 9907093804 Top Class Call Girl Service Available
 
Chandrapur Call girls 8617370543 Provides all area service COD available
Chandrapur Call girls 8617370543 Provides all area service COD availableChandrapur Call girls 8617370543 Provides all area service COD available
Chandrapur Call girls 8617370543 Provides all area service COD available
 
Call Girls Nagpur Just Call 9907093804 Top Class Call Girl Service Available
Call Girls Nagpur Just Call 9907093804 Top Class Call Girl Service AvailableCall Girls Nagpur Just Call 9907093804 Top Class Call Girl Service Available
Call Girls Nagpur Just Call 9907093804 Top Class Call Girl Service Available
 
Russian Call Girls in Jaipur Riya WhatsApp ❤8445551418 VIP Call Girls Jaipur
Russian Call Girls in Jaipur Riya WhatsApp ❤8445551418 VIP Call Girls JaipurRussian Call Girls in Jaipur Riya WhatsApp ❤8445551418 VIP Call Girls Jaipur
Russian Call Girls in Jaipur Riya WhatsApp ❤8445551418 VIP Call Girls Jaipur
 
Call Girls Ooty Just Call 9907093804 Top Class Call Girl Service Available
Call Girls Ooty Just Call 9907093804 Top Class Call Girl Service AvailableCall Girls Ooty Just Call 9907093804 Top Class Call Girl Service Available
Call Girls Ooty Just Call 9907093804 Top Class Call Girl Service Available
 
Lucknow Call girls - 8800925952 - 24x7 service with hotel room
Lucknow Call girls - 8800925952 - 24x7 service with hotel roomLucknow Call girls - 8800925952 - 24x7 service with hotel room
Lucknow Call girls - 8800925952 - 24x7 service with hotel room
 
Top Quality Call Girl Service Kalyanpur 6378878445 Available Call Girls Any Time
Top Quality Call Girl Service Kalyanpur 6378878445 Available Call Girls Any TimeTop Quality Call Girl Service Kalyanpur 6378878445 Available Call Girls Any Time
Top Quality Call Girl Service Kalyanpur 6378878445 Available Call Girls Any Time
 
Call Girls Dehradun Just Call 9907093804 Top Class Call Girl Service Available
Call Girls Dehradun Just Call 9907093804 Top Class Call Girl Service AvailableCall Girls Dehradun Just Call 9907093804 Top Class Call Girl Service Available
Call Girls Dehradun Just Call 9907093804 Top Class Call Girl Service Available
 
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...
 
♛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 ...
 
Call Girls Horamavu WhatsApp Number 7001035870 Meeting With Bangalore Escorts
Call Girls Horamavu WhatsApp Number 7001035870 Meeting With Bangalore EscortsCall Girls Horamavu WhatsApp Number 7001035870 Meeting With Bangalore Escorts
Call Girls Horamavu WhatsApp Number 7001035870 Meeting With Bangalore Escorts
 
Call Girls Faridabad Just Call 9907093804 Top Class Call Girl Service Available
Call Girls Faridabad Just Call 9907093804 Top Class Call Girl Service AvailableCall Girls Faridabad Just Call 9907093804 Top Class Call Girl Service Available
Call Girls Faridabad Just Call 9907093804 Top Class Call Girl Service Available
 
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...
 
Call Girls Visakhapatnam Just Call 9907093804 Top Class Call Girl Service Ava...
Call Girls Visakhapatnam Just Call 9907093804 Top Class Call Girl Service Ava...Call Girls Visakhapatnam Just Call 9907093804 Top Class Call Girl Service Ava...
Call Girls Visakhapatnam Just Call 9907093804 Top Class Call Girl Service Ava...
 
College Call Girls in Haridwar 9667172968 Short 4000 Night 10000 Best call gi...
College Call Girls in Haridwar 9667172968 Short 4000 Night 10000 Best call gi...College Call Girls in Haridwar 9667172968 Short 4000 Night 10000 Best call gi...
College Call Girls in Haridwar 9667172968 Short 4000 Night 10000 Best call gi...
 
All Time Service Available Call Girls Marine Drive 📳 9820252231 For 18+ VIP C...
All Time Service Available Call Girls Marine Drive 📳 9820252231 For 18+ VIP C...All Time Service Available Call Girls Marine Drive 📳 9820252231 For 18+ VIP C...
All Time Service Available Call Girls Marine Drive 📳 9820252231 For 18+ VIP C...
 

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.