SlideShare a Scribd company logo
1 of 4
Chapter 8 Objects and Classes
1. See the section "Declaring and Creating Objects."
2. Constructors are special kinds of methods that are
called when creating an object using the new operator.
Constructors do not have a return type—not even void.
3. An array is an object. The default value for the
elements of an array is 0 for numeric, false for
boolean, ‘u0000’ for char, null for object element
type.
4. (a) There is such constructor ShowErrors(int) in the
ShowErrors class.
The ShowErrors class in the book has a default
constructor. It is actually same as
public class ShowErrors {
public static void main(String[] args) {
ShowErrors t = new ShowErrors(5);
}
public ShowErrors () {
}
}
On Line 3, new ShowErrors(5) attempts to create an
instance using a constructor ShowErrors(int), but the
ShowErrors class does not have such a constructor.
That is an error.
(b) x() is not a method in the ShowErrors class.
The ShowErrors class in the book has a default
constructor. It is actually same as
public class ShowErrors {
public static void main(String[] args) {
ShowErrors t = new ShowErrors();
t.x();
}
public ShowErrors () {
}
}
On Line 4, t.x() is invoked, but the ShowErrors class
does not have the method named x(). That is an error.
(c) The program compiles fine, but it has a runtime
error because variable c is null when the println
statement is executed.
(d) new C(5.0) does not match any constructors in
class C. The program has a compilation error because
class C does not have a constructor with a double
argument.
5. The program does not compile because new A() is used in
class Test, but class A does not have a default
constructor. See the second NOTE in the Section,
“Constructors.”
6. false
7. Use the Date’s no-arg constructor to create a Date for
the current time. Use the Date’s toString() method to
display a string representation for the Date.
8. Use the JFrame’s no-arg constructor to create JFrame. Use
the setTitle(String) method a set a title and use the
setVisible(true) method to display the frame.
9. Date is in java.util. JFrame and JOptionPane are in
javax.swing. System and Math are in java.lang.
10. System.out.println(f.i);
Answer: Correct
System.out.println(f.s);
Answer: Correct
f.imethod();
Answer: Correct
f.smethod();
Answer: Correct
System.out.println(Foo.i);
Answer: Incorrect
System.out.println(Foo.s);
Answer: Correct
Foo.imethod();
Answer: Incorrect
Foo.smethod();
Answer: Correct
11. Add static in the main method and in the factorial
method because these two methods don’t need reference
any instance objects or invoke any instance methods in
the Test class.
12. You cannot invoke an instance method or reference an
instance variable from a static method. You can invoke a
static method or reference a static variable from an
instance method? c is an instance variable, which cannot
be accessed from the static context in method2.
13. Accessor method is for retrieving private data value
and mutator method is for changing private data value. The
naming convention for accessor method is getDataFieldName() for
non-boolean values and isDataFieldName() for boolean values. The
naming convention for mutator method is setDataFieldName(value).
14.Two benefits: (1) for protecting data and (2) for easy
to maintain the class.
15. Yes. Though radius is private, myCircle.radius is used
inside the Circle class. Thus, it is fine.
16. Java uses “pass by value” to pass parameters to a
method. When passing a variable of a primitive type to
a method, the variable remains unchanged after the
method finishes. However, when passing a variable of a
reference type to a method, any changes to the object
referenced by the variable inside the method are
permanent changes to the object referenced by the
variable outside of the method. Both the actual
parameter and the formal parameter variables reference
to the same object.
The output of the program is as follows:
count 101
times 0
17.
Remark: The reference value of circle1 is passed to x and
the reference value of circle2 is passed to y. The contents of
the objects are not swapped in the swap1 method. circle1 and
circle2 are not swapped. To actually swap the contents of these
objects, replace the following three lines
Circle temp = x;
x =y;
y =temp;
by
double temp = x.radius;
x.radius = y.radius;
y.radius = temp;
as in swap2.
18. a. a[0] = 1 a[1] = 2
b. a[0] = 2 a[1] = 1
c. e1 = 2 e2 = 1
d. t1’s i = 2 t1’s j = 1
t2’s i = 2 t2’s j = 1
19. (a) null
(b) 1234567
(c) 7654321
(d) 1234567
20. (Line 4 prints null since dates[0] is null. Line 5
causes a NullPointerException since it invokes toString() method
from the null reference.)

More Related Content

What's hot

Class notes(week 3) on class objects and methods
Class notes(week 3) on class objects and methodsClass notes(week 3) on class objects and methods
Class notes(week 3) on class objects and methodsKuntal Bhowmick
 
3 searching algorithms in Java
3 searching algorithms in Java3 searching algorithms in Java
3 searching algorithms in JavaMahmoud Alfarra
 
L11 array list
L11 array listL11 array list
L11 array listteach4uin
 
Class notes(week 3) on class objects and methods
Class notes(week 3) on class objects and methodsClass notes(week 3) on class objects and methods
Class notes(week 3) on class objects and methodsKuntal Bhowmick
 
香港六合彩
香港六合彩香港六合彩
香港六合彩cctv
 
Avoid creating unncessary objects
Avoid creating unncessary objectsAvoid creating unncessary objects
Avoid creating unncessary objectsYe Win
 
(6) collections algorithms
(6) collections algorithms(6) collections algorithms
(6) collections algorithmsNico Ludwig
 
Effective Java - Chapter 3: Methods Common to All Objects
Effective Java - Chapter 3: Methods Common to All ObjectsEffective Java - Chapter 3: Methods Common to All Objects
Effective Java - Chapter 3: Methods Common to All Objectsİbrahim Kürce
 
Chapter 5:Understanding Variable Scope and Class Construction
Chapter 5:Understanding Variable Scope and Class ConstructionChapter 5:Understanding Variable Scope and Class Construction
Chapter 5:Understanding Variable Scope and Class ConstructionIt Academy
 
Quiz2 cs141-1-17
Quiz2 cs141-1-17Quiz2 cs141-1-17
Quiz2 cs141-1-17Fahadaio
 

What's hot (20)

Class notes(week 3) on class objects and methods
Class notes(week 3) on class objects and methodsClass notes(week 3) on class objects and methods
Class notes(week 3) on class objects and methods
 
3 searching algorithms in Java
3 searching algorithms in Java3 searching algorithms in Java
3 searching algorithms in Java
 
L11 array list
L11 array listL11 array list
L11 array list
 
CRMS Calculus 2010 February 8, 2010_B
CRMS Calculus 2010 February 8, 2010_BCRMS Calculus 2010 February 8, 2010_B
CRMS Calculus 2010 February 8, 2010_B
 
Functions
FunctionsFunctions
Functions
 
Kelompok 8 Pbw
Kelompok 8 PbwKelompok 8 Pbw
Kelompok 8 Pbw
 
Kelompok 8 Pbw
Kelompok 8 PbwKelompok 8 Pbw
Kelompok 8 Pbw
 
Visual basic bt0082
Visual basic  bt0082Visual basic  bt0082
Visual basic bt0082
 
Class notes(week 3) on class objects and methods
Class notes(week 3) on class objects and methodsClass notes(week 3) on class objects and methods
Class notes(week 3) on class objects and methods
 
A04
A04A04
A04
 
Insertion sort algorithm power point presentation
Insertion  sort algorithm power point presentation Insertion  sort algorithm power point presentation
Insertion sort algorithm power point presentation
 
searching
searchingsearching
searching
 
Selection sort algorithm presentation, selection sort example using power point
Selection sort algorithm presentation, selection sort example using power point Selection sort algorithm presentation, selection sort example using power point
Selection sort algorithm presentation, selection sort example using power point
 
香港六合彩
香港六合彩香港六合彩
香港六合彩
 
Java execise
Java execiseJava execise
Java execise
 
Avoid creating unncessary objects
Avoid creating unncessary objectsAvoid creating unncessary objects
Avoid creating unncessary objects
 
(6) collections algorithms
(6) collections algorithms(6) collections algorithms
(6) collections algorithms
 
Effective Java - Chapter 3: Methods Common to All Objects
Effective Java - Chapter 3: Methods Common to All ObjectsEffective Java - Chapter 3: Methods Common to All Objects
Effective Java - Chapter 3: Methods Common to All Objects
 
Chapter 5:Understanding Variable Scope and Class Construction
Chapter 5:Understanding Variable Scope and Class ConstructionChapter 5:Understanding Variable Scope and Class Construction
Chapter 5:Understanding Variable Scope and Class Construction
 
Quiz2 cs141-1-17
Quiz2 cs141-1-17Quiz2 cs141-1-17
Quiz2 cs141-1-17
 

Viewers also liked

Peraturan am mengisi dokumen perjanjian
Peraturan am mengisi dokumen perjanjianPeraturan am mengisi dokumen perjanjian
Peraturan am mengisi dokumen perjanjianIIUM
 
Project part 2 instructions
Project part 2   instructionsProject part 2   instructions
Project part 2 instructionsIIUM
 
Lect 18
Lect 18Lect 18
Lect 18IIUM
 
Ibm piquant summary
Ibm piquant summaryIbm piquant summary
Ibm piquant summaryIIUM
 
Principle and Practice of Management MGT Ippt chap006
Principle and Practice of Management MGT Ippt chap006Principle and Practice of Management MGT Ippt chap006
Principle and Practice of Management MGT Ippt chap006IIUM
 
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
 
Principle and Practice of Management MGT Ippt chap010
Principle and Practice of Management MGT Ippt chap010Principle and Practice of Management MGT Ippt chap010
Principle and Practice of Management MGT Ippt chap010IIUM
 
Project final
Project finalProject final
Project finalIIUM
 
Csc1100 elements of programming (revised july 2014) 120lh-2-student
Csc1100 elements of  programming (revised july 2014) 120lh-2-studentCsc1100 elements of  programming (revised july 2014) 120lh-2-student
Csc1100 elements of programming (revised july 2014) 120lh-2-studentIIUM
 
Csc1401 q1 - sect3 - answers scheme
Csc1401   q1 - sect3 - answers schemeCsc1401   q1 - sect3 - answers scheme
Csc1401 q1 - sect3 - answers schemeIIUM
 
Assignment 01
Assignment 01Assignment 01
Assignment 01IIUM
 
Mid term sem 2 1415 sol
Mid term sem 2 1415 solMid term sem 2 1415 sol
Mid term sem 2 1415 solIIUM
 
Csc1100 lecture02 ch02-datatype_declaration
Csc1100 lecture02 ch02-datatype_declarationCsc1100 lecture02 ch02-datatype_declaration
Csc1100 lecture02 ch02-datatype_declarationIIUM
 
Redo midterm
Redo midtermRedo midterm
Redo midtermIIUM
 
Principle and Practice of Management MGT Ippt chap001
Principle and Practice of Management MGT Ippt chap001Principle and Practice of Management MGT Ippt chap001
Principle and Practice of Management MGT Ippt chap001IIUM
 
Chapter 6 1
Chapter 6 1Chapter 6 1
Chapter 6 1IIUM
 
Heaps
HeapsHeaps
HeapsIIUM
 
Introduction fundamentals sets and sequences
Introduction  fundamentals sets and sequencesIntroduction  fundamentals sets and sequences
Introduction fundamentals sets and sequencesIIUM
 

Viewers also liked (18)

Peraturan am mengisi dokumen perjanjian
Peraturan am mengisi dokumen perjanjianPeraturan am mengisi dokumen perjanjian
Peraturan am mengisi dokumen perjanjian
 
Project part 2 instructions
Project part 2   instructionsProject part 2   instructions
Project part 2 instructions
 
Lect 18
Lect 18Lect 18
Lect 18
 
Ibm piquant summary
Ibm piquant summaryIbm piquant summary
Ibm piquant summary
 
Principle and Practice of Management MGT Ippt chap006
Principle and Practice of Management MGT Ippt chap006Principle and Practice of Management MGT Ippt chap006
Principle and Practice of Management MGT Ippt chap006
 
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
 
Principle and Practice of Management MGT Ippt chap010
Principle and Practice of Management MGT Ippt chap010Principle and Practice of Management MGT Ippt chap010
Principle and Practice of Management MGT Ippt chap010
 
Project final
Project finalProject final
Project final
 
Csc1100 elements of programming (revised july 2014) 120lh-2-student
Csc1100 elements of  programming (revised july 2014) 120lh-2-studentCsc1100 elements of  programming (revised july 2014) 120lh-2-student
Csc1100 elements of programming (revised july 2014) 120lh-2-student
 
Csc1401 q1 - sect3 - answers scheme
Csc1401   q1 - sect3 - answers schemeCsc1401   q1 - sect3 - answers scheme
Csc1401 q1 - sect3 - answers scheme
 
Assignment 01
Assignment 01Assignment 01
Assignment 01
 
Mid term sem 2 1415 sol
Mid term sem 2 1415 solMid term sem 2 1415 sol
Mid term sem 2 1415 sol
 
Csc1100 lecture02 ch02-datatype_declaration
Csc1100 lecture02 ch02-datatype_declarationCsc1100 lecture02 ch02-datatype_declaration
Csc1100 lecture02 ch02-datatype_declaration
 
Redo midterm
Redo midtermRedo midterm
Redo midterm
 
Principle and Practice of Management MGT Ippt chap001
Principle and Practice of Management MGT Ippt chap001Principle and Practice of Management MGT Ippt chap001
Principle and Practice of Management MGT Ippt chap001
 
Chapter 6 1
Chapter 6 1Chapter 6 1
Chapter 6 1
 
Heaps
HeapsHeaps
Heaps
 
Introduction fundamentals sets and sequences
Introduction  fundamentals sets and sequencesIntroduction  fundamentals sets and sequences
Introduction fundamentals sets and sequences
 

Similar to 08review (1)

14review(abstract classandinterfaces)
14review(abstract classandinterfaces)14review(abstract classandinterfaces)
14review(abstract classandinterfaces)IIUM
 
Ecet 370 Education Organization -- snaptutorial.com
Ecet 370   Education Organization -- snaptutorial.comEcet 370   Education Organization -- snaptutorial.com
Ecet 370 Education Organization -- snaptutorial.comDavisMurphyB81
 
ECET 370 Exceptional Education - snaptutorial.com
ECET 370 Exceptional Education - snaptutorial.com ECET 370 Exceptional Education - snaptutorial.com
ECET 370 Exceptional Education - snaptutorial.com donaldzs157
 
packages and interfaces
packages and interfacespackages and interfaces
packages and interfacesmadhavi patil
 
Class and Object.pptx
Class and Object.pptxClass and Object.pptx
Class and Object.pptxHailsh
 
Chap-2 Classes & Methods.pptx
Chap-2 Classes & Methods.pptxChap-2 Classes & Methods.pptx
Chap-2 Classes & Methods.pptxchetanpatilcp783
 
15review(abstract classandinterfaces)
15review(abstract classandinterfaces)15review(abstract classandinterfaces)
15review(abstract classandinterfaces)IIUM
 
Autoboxing and unboxing
Autoboxing and unboxingAutoboxing and unboxing
Autoboxing and unboxingGeetha Manohar
 
chap 8 : The java.lang and java.util Packages (scjp/ocjp)
chap 8 : The java.lang and java.util Packages (scjp/ocjp)chap 8 : The java.lang and java.util Packages (scjp/ocjp)
chap 8 : The java.lang and java.util Packages (scjp/ocjp)It Academy
 

Similar to 08review (1) (20)

Ch-2ppt.pptx
Ch-2ppt.pptxCh-2ppt.pptx
Ch-2ppt.pptx
 
14review(abstract classandinterfaces)
14review(abstract classandinterfaces)14review(abstract classandinterfaces)
14review(abstract classandinterfaces)
 
Constructors
ConstructorsConstructors
Constructors
 
JAVA CONCEPTS
JAVA CONCEPTS JAVA CONCEPTS
JAVA CONCEPTS
 
Ecet 370 Education Organization -- snaptutorial.com
Ecet 370   Education Organization -- snaptutorial.comEcet 370   Education Organization -- snaptutorial.com
Ecet 370 Education Organization -- snaptutorial.com
 
ECET 370 Exceptional Education - snaptutorial.com
ECET 370 Exceptional Education - snaptutorial.com ECET 370 Exceptional Education - snaptutorial.com
ECET 370 Exceptional Education - snaptutorial.com
 
packages and interfaces
packages and interfacespackages and interfaces
packages and interfaces
 
Class and Object.pptx
Class and Object.pptxClass and Object.pptx
Class and Object.pptx
 
Wrapper classes
Wrapper classesWrapper classes
Wrapper classes
 
Collections
CollectionsCollections
Collections
 
Java Programming - 04 object oriented in java
Java Programming - 04 object oriented in javaJava Programming - 04 object oriented in java
Java Programming - 04 object oriented in java
 
Chap-2 Classes & Methods.pptx
Chap-2 Classes & Methods.pptxChap-2 Classes & Methods.pptx
Chap-2 Classes & Methods.pptx
 
Java String
Java String Java String
Java String
 
Lecture 5
Lecture 5Lecture 5
Lecture 5
 
15review(abstract classandinterfaces)
15review(abstract classandinterfaces)15review(abstract classandinterfaces)
15review(abstract classandinterfaces)
 
CPP Homework Help
CPP Homework HelpCPP Homework Help
CPP Homework Help
 
Autoboxing and unboxing
Autoboxing and unboxingAutoboxing and unboxing
Autoboxing and unboxing
 
basic concepts
basic conceptsbasic concepts
basic concepts
 
chap 8 : The java.lang and java.util Packages (scjp/ocjp)
chap 8 : The java.lang and java.util Packages (scjp/ocjp)chap 8 : The java.lang and java.util Packages (scjp/ocjp)
chap 8 : The java.lang and java.util Packages (scjp/ocjp)
 
Imp_Points_Scala
Imp_Points_ScalaImp_Points_Scala
Imp_Points_Scala
 

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
 
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
 
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
 
Vpn
VpnVpn
VpnIIUM
 
Principle and Practice of Management MGT Ippt chap002
Principle and Practice of Management MGT Ippt chap002Principle and Practice of Management MGT Ippt chap002
Principle and Practice of Management MGT Ippt chap002IIUM
 
Principle and Practice of Management MGT Ippt chap003
Principle and Practice of Management MGT Ippt chap003Principle and Practice of Management MGT Ippt chap003
Principle and Practice of Management MGT Ippt chap003IIUM
 

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
 
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
 
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
 
Vpn
VpnVpn
Vpn
 
Principle and Practice of Management MGT Ippt chap002
Principle and Practice of Management MGT Ippt chap002Principle and Practice of Management MGT Ippt chap002
Principle and Practice of Management MGT Ippt chap002
 
Principle and Practice of Management MGT Ippt chap003
Principle and Practice of Management MGT Ippt chap003Principle and Practice of Management MGT Ippt chap003
Principle and Practice of Management MGT Ippt chap003
 

Recently uploaded

VIP High Class Call Girls Amravati Anushka 8250192130 Independent Escort Serv...
VIP High Class Call Girls Amravati Anushka 8250192130 Independent Escort Serv...VIP High Class Call Girls Amravati Anushka 8250192130 Independent Escort Serv...
VIP High Class Call Girls Amravati Anushka 8250192130 Independent Escort Serv...Suhani Kapoor
 
2024 Zoom Reinstein Legacy Asbestos Webinar
2024 Zoom Reinstein Legacy Asbestos Webinar2024 Zoom Reinstein Legacy Asbestos Webinar
2024 Zoom Reinstein Legacy Asbestos WebinarLinda Reinstein
 
(ANIKA) Call Girls Wadki ( 7001035870 ) HI-Fi Pune Escorts Service
(ANIKA) Call Girls Wadki ( 7001035870 ) HI-Fi Pune Escorts Service(ANIKA) Call Girls Wadki ( 7001035870 ) HI-Fi Pune Escorts Service
(ANIKA) Call Girls Wadki ( 7001035870 ) HI-Fi Pune Escorts Serviceranjana rawat
 
VIP Kolkata Call Girl Jatin Das Park 👉 8250192130 Available With Room
VIP Kolkata Call Girl Jatin Das Park 👉 8250192130  Available With RoomVIP Kolkata Call Girl Jatin Das Park 👉 8250192130  Available With Room
VIP Kolkata Call Girl Jatin Das Park 👉 8250192130 Available With Roomishabajaj13
 
2024: The FAR, Federal Acquisition Regulations - Part 28
2024: The FAR, Federal Acquisition Regulations - Part 282024: The FAR, Federal Acquisition Regulations - Part 28
2024: The FAR, Federal Acquisition Regulations - Part 28JSchaus & Associates
 
Artificial Intelligence in Philippine Local Governance: Challenges and Opport...
Artificial Intelligence in Philippine Local Governance: Challenges and Opport...Artificial Intelligence in Philippine Local Governance: Challenges and Opport...
Artificial Intelligence in Philippine Local Governance: Challenges and Opport...CedZabala
 
(DIVYA) Call Girls Wakad ( 7001035870 ) HI-Fi Pune Escorts Service
(DIVYA) Call Girls Wakad ( 7001035870 ) HI-Fi Pune Escorts Service(DIVYA) Call Girls Wakad ( 7001035870 ) HI-Fi Pune Escorts Service
(DIVYA) Call Girls Wakad ( 7001035870 ) HI-Fi Pune Escorts Serviceranjana rawat
 
2024: The FAR, Federal Acquisition Regulations - Part 29
2024: The FAR, Federal Acquisition Regulations - Part 292024: The FAR, Federal Acquisition Regulations - Part 29
2024: The FAR, Federal Acquisition Regulations - Part 29JSchaus & Associates
 
2024: The FAR, Federal Acquisition Regulations - Part 27
2024: The FAR, Federal Acquisition Regulations - Part 272024: The FAR, Federal Acquisition Regulations - Part 27
2024: The FAR, Federal Acquisition Regulations - Part 27JSchaus & Associates
 
Climate change and occupational safety and health.
Climate change and occupational safety and health.Climate change and occupational safety and health.
Climate change and occupational safety and health.Christina Parmionova
 
Fair Trash Reduction - West Hartford, CT
Fair Trash Reduction - West Hartford, CTFair Trash Reduction - West Hartford, CT
Fair Trash Reduction - West Hartford, CTaccounts329278
 
Regional Snapshot Atlanta Aging Trends 2024
Regional Snapshot Atlanta Aging Trends 2024Regional Snapshot Atlanta Aging Trends 2024
Regional Snapshot Atlanta Aging Trends 2024ARCResearch
 
Incident Command System xxxxxxxxxxxxxxxxxxxxxxxxx
Incident Command System xxxxxxxxxxxxxxxxxxxxxxxxxIncident Command System xxxxxxxxxxxxxxxxxxxxxxxxx
Incident Command System xxxxxxxxxxxxxxxxxxxxxxxxxPeter Miles
 
(VASUDHA) Call Girls Balaji Nagar ( 7001035870 ) HI-Fi Pune Escorts Service
(VASUDHA) Call Girls Balaji Nagar ( 7001035870 ) HI-Fi Pune Escorts Service(VASUDHA) Call Girls Balaji Nagar ( 7001035870 ) HI-Fi Pune Escorts Service
(VASUDHA) Call Girls Balaji Nagar ( 7001035870 ) HI-Fi Pune Escorts Serviceranjana rawat
 
(TARA) Call Girls Chakan ( 7001035870 ) HI-Fi Pune Escorts Service
(TARA) Call Girls Chakan ( 7001035870 ) HI-Fi Pune Escorts Service(TARA) Call Girls Chakan ( 7001035870 ) HI-Fi Pune Escorts Service
(TARA) Call Girls Chakan ( 7001035870 ) HI-Fi Pune Escorts Serviceranjana rawat
 
EDUROOT SME_ Performance upto March-2024.pptx
EDUROOT SME_ Performance upto March-2024.pptxEDUROOT SME_ Performance upto March-2024.pptx
EDUROOT SME_ Performance upto March-2024.pptxaaryamanorathofficia
 
DNV publication: China Energy Transition Outlook 2024
DNV publication: China Energy Transition Outlook 2024DNV publication: China Energy Transition Outlook 2024
DNV publication: China Energy Transition Outlook 2024Energy for One World
 
##9711199012 Call Girls Delhi Rs-5000 UpTo 10 K Hauz Khas Whats Up Number
##9711199012 Call Girls Delhi Rs-5000 UpTo 10 K Hauz Khas  Whats Up Number##9711199012 Call Girls Delhi Rs-5000 UpTo 10 K Hauz Khas  Whats Up Number
##9711199012 Call Girls Delhi Rs-5000 UpTo 10 K Hauz Khas Whats Up NumberMs Riya
 
VIP Call Girls Pune Vani 8617697112 Independent Escort Service Pune
VIP Call Girls Pune Vani 8617697112 Independent Escort Service PuneVIP Call Girls Pune Vani 8617697112 Independent Escort Service Pune
VIP Call Girls Pune Vani 8617697112 Independent Escort Service PuneCall girls in Ahmedabad High profile
 

Recently uploaded (20)

VIP High Class Call Girls Amravati Anushka 8250192130 Independent Escort Serv...
VIP High Class Call Girls Amravati Anushka 8250192130 Independent Escort Serv...VIP High Class Call Girls Amravati Anushka 8250192130 Independent Escort Serv...
VIP High Class Call Girls Amravati Anushka 8250192130 Independent Escort Serv...
 
2024 Zoom Reinstein Legacy Asbestos Webinar
2024 Zoom Reinstein Legacy Asbestos Webinar2024 Zoom Reinstein Legacy Asbestos Webinar
2024 Zoom Reinstein Legacy Asbestos Webinar
 
(ANIKA) Call Girls Wadki ( 7001035870 ) HI-Fi Pune Escorts Service
(ANIKA) Call Girls Wadki ( 7001035870 ) HI-Fi Pune Escorts Service(ANIKA) Call Girls Wadki ( 7001035870 ) HI-Fi Pune Escorts Service
(ANIKA) Call Girls Wadki ( 7001035870 ) HI-Fi Pune Escorts Service
 
VIP Kolkata Call Girl Jatin Das Park 👉 8250192130 Available With Room
VIP Kolkata Call Girl Jatin Das Park 👉 8250192130  Available With RoomVIP Kolkata Call Girl Jatin Das Park 👉 8250192130  Available With Room
VIP Kolkata Call Girl Jatin Das Park 👉 8250192130 Available With Room
 
2024: The FAR, Federal Acquisition Regulations - Part 28
2024: The FAR, Federal Acquisition Regulations - Part 282024: The FAR, Federal Acquisition Regulations - Part 28
2024: The FAR, Federal Acquisition Regulations - Part 28
 
Artificial Intelligence in Philippine Local Governance: Challenges and Opport...
Artificial Intelligence in Philippine Local Governance: Challenges and Opport...Artificial Intelligence in Philippine Local Governance: Challenges and Opport...
Artificial Intelligence in Philippine Local Governance: Challenges and Opport...
 
(DIVYA) Call Girls Wakad ( 7001035870 ) HI-Fi Pune Escorts Service
(DIVYA) Call Girls Wakad ( 7001035870 ) HI-Fi Pune Escorts Service(DIVYA) Call Girls Wakad ( 7001035870 ) HI-Fi Pune Escorts Service
(DIVYA) Call Girls Wakad ( 7001035870 ) HI-Fi Pune Escorts Service
 
2024: The FAR, Federal Acquisition Regulations - Part 29
2024: The FAR, Federal Acquisition Regulations - Part 292024: The FAR, Federal Acquisition Regulations - Part 29
2024: The FAR, Federal Acquisition Regulations - Part 29
 
2024: The FAR, Federal Acquisition Regulations - Part 27
2024: The FAR, Federal Acquisition Regulations - Part 272024: The FAR, Federal Acquisition Regulations - Part 27
2024: The FAR, Federal Acquisition Regulations - Part 27
 
Climate change and occupational safety and health.
Climate change and occupational safety and health.Climate change and occupational safety and health.
Climate change and occupational safety and health.
 
Fair Trash Reduction - West Hartford, CT
Fair Trash Reduction - West Hartford, CTFair Trash Reduction - West Hartford, CT
Fair Trash Reduction - West Hartford, CT
 
How to Save a Place: 12 Tips To Research & Know the Threat
How to Save a Place: 12 Tips To Research & Know the ThreatHow to Save a Place: 12 Tips To Research & Know the Threat
How to Save a Place: 12 Tips To Research & Know the Threat
 
Regional Snapshot Atlanta Aging Trends 2024
Regional Snapshot Atlanta Aging Trends 2024Regional Snapshot Atlanta Aging Trends 2024
Regional Snapshot Atlanta Aging Trends 2024
 
Incident Command System xxxxxxxxxxxxxxxxxxxxxxxxx
Incident Command System xxxxxxxxxxxxxxxxxxxxxxxxxIncident Command System xxxxxxxxxxxxxxxxxxxxxxxxx
Incident Command System xxxxxxxxxxxxxxxxxxxxxxxxx
 
(VASUDHA) Call Girls Balaji Nagar ( 7001035870 ) HI-Fi Pune Escorts Service
(VASUDHA) Call Girls Balaji Nagar ( 7001035870 ) HI-Fi Pune Escorts Service(VASUDHA) Call Girls Balaji Nagar ( 7001035870 ) HI-Fi Pune Escorts Service
(VASUDHA) Call Girls Balaji Nagar ( 7001035870 ) HI-Fi Pune Escorts Service
 
(TARA) Call Girls Chakan ( 7001035870 ) HI-Fi Pune Escorts Service
(TARA) Call Girls Chakan ( 7001035870 ) HI-Fi Pune Escorts Service(TARA) Call Girls Chakan ( 7001035870 ) HI-Fi Pune Escorts Service
(TARA) Call Girls Chakan ( 7001035870 ) HI-Fi Pune Escorts Service
 
EDUROOT SME_ Performance upto March-2024.pptx
EDUROOT SME_ Performance upto March-2024.pptxEDUROOT SME_ Performance upto March-2024.pptx
EDUROOT SME_ Performance upto March-2024.pptx
 
DNV publication: China Energy Transition Outlook 2024
DNV publication: China Energy Transition Outlook 2024DNV publication: China Energy Transition Outlook 2024
DNV publication: China Energy Transition Outlook 2024
 
##9711199012 Call Girls Delhi Rs-5000 UpTo 10 K Hauz Khas Whats Up Number
##9711199012 Call Girls Delhi Rs-5000 UpTo 10 K Hauz Khas  Whats Up Number##9711199012 Call Girls Delhi Rs-5000 UpTo 10 K Hauz Khas  Whats Up Number
##9711199012 Call Girls Delhi Rs-5000 UpTo 10 K Hauz Khas Whats Up Number
 
VIP Call Girls Pune Vani 8617697112 Independent Escort Service Pune
VIP Call Girls Pune Vani 8617697112 Independent Escort Service PuneVIP Call Girls Pune Vani 8617697112 Independent Escort Service Pune
VIP Call Girls Pune Vani 8617697112 Independent Escort Service Pune
 

08review (1)

  • 1. Chapter 8 Objects and Classes 1. See the section "Declaring and Creating Objects." 2. Constructors are special kinds of methods that are called when creating an object using the new operator. Constructors do not have a return type—not even void. 3. An array is an object. The default value for the elements of an array is 0 for numeric, false for boolean, ‘u0000’ for char, null for object element type. 4. (a) There is such constructor ShowErrors(int) in the ShowErrors class. The ShowErrors class in the book has a default constructor. It is actually same as public class ShowErrors { public static void main(String[] args) { ShowErrors t = new ShowErrors(5); } public ShowErrors () { } } On Line 3, new ShowErrors(5) attempts to create an instance using a constructor ShowErrors(int), but the ShowErrors class does not have such a constructor. That is an error. (b) x() is not a method in the ShowErrors class. The ShowErrors class in the book has a default constructor. It is actually same as public class ShowErrors { public static void main(String[] args) { ShowErrors t = new ShowErrors(); t.x(); } public ShowErrors () {
  • 2. } } On Line 4, t.x() is invoked, but the ShowErrors class does not have the method named x(). That is an error. (c) The program compiles fine, but it has a runtime error because variable c is null when the println statement is executed. (d) new C(5.0) does not match any constructors in class C. The program has a compilation error because class C does not have a constructor with a double argument. 5. The program does not compile because new A() is used in class Test, but class A does not have a default constructor. See the second NOTE in the Section, “Constructors.” 6. false 7. Use the Date’s no-arg constructor to create a Date for the current time. Use the Date’s toString() method to display a string representation for the Date. 8. Use the JFrame’s no-arg constructor to create JFrame. Use the setTitle(String) method a set a title and use the setVisible(true) method to display the frame. 9. Date is in java.util. JFrame and JOptionPane are in javax.swing. System and Math are in java.lang. 10. System.out.println(f.i); Answer: Correct System.out.println(f.s); Answer: Correct f.imethod(); Answer: Correct f.smethod(); Answer: Correct System.out.println(Foo.i); Answer: Incorrect
  • 3. System.out.println(Foo.s); Answer: Correct Foo.imethod(); Answer: Incorrect Foo.smethod(); Answer: Correct 11. Add static in the main method and in the factorial method because these two methods don’t need reference any instance objects or invoke any instance methods in the Test class. 12. You cannot invoke an instance method or reference an instance variable from a static method. You can invoke a static method or reference a static variable from an instance method? c is an instance variable, which cannot be accessed from the static context in method2. 13. Accessor method is for retrieving private data value and mutator method is for changing private data value. The naming convention for accessor method is getDataFieldName() for non-boolean values and isDataFieldName() for boolean values. The naming convention for mutator method is setDataFieldName(value). 14.Two benefits: (1) for protecting data and (2) for easy to maintain the class. 15. Yes. Though radius is private, myCircle.radius is used inside the Circle class. Thus, it is fine. 16. Java uses “pass by value” to pass parameters to a method. When passing a variable of a primitive type to a method, the variable remains unchanged after the method finishes. However, when passing a variable of a reference type to a method, any changes to the object referenced by the variable inside the method are permanent changes to the object referenced by the variable outside of the method. Both the actual parameter and the formal parameter variables reference to the same object. The output of the program is as follows: count 101 times 0
  • 4. 17. Remark: The reference value of circle1 is passed to x and the reference value of circle2 is passed to y. The contents of the objects are not swapped in the swap1 method. circle1 and circle2 are not swapped. To actually swap the contents of these objects, replace the following three lines Circle temp = x; x =y; y =temp; by double temp = x.radius; x.radius = y.radius; y.radius = temp; as in swap2. 18. a. a[0] = 1 a[1] = 2 b. a[0] = 2 a[1] = 1 c. e1 = 2 e2 = 1 d. t1’s i = 2 t1’s j = 1 t2’s i = 2 t2’s j = 1 19. (a) null (b) 1234567 (c) 7654321 (d) 1234567 20. (Line 4 prints null since dates[0] is null. Line 5 causes a NullPointerException since it invokes toString() method from the null reference.)