Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Can I get a help with These question? Thanks. 1-What are some things wrong with the following code? (Don't bother trying to understand what this

Can I get a help with These question? Thanks.

1-What are some things wrong with the following code? (Don't bother trying to understand what this method is doing.)

149 String silly(Point p) { 150 if (p == null) throw new IllegalArgumentException("p can't be null"); 151 String result; 152 Point last = null; 153 while (p.getX() > 0) { 154 last = p; 155 p = new Point(p.getX()-p.getY(),p.getY()+1); 156 if (p.getY() < 0) { 157 result = "Found negative"; 158 p = null; 159 break; 160 } 161 } 162 return result + "last,x = " + last.getX() + ", p = " + p; 163 } Select all that apply:

a) At line 158, p is assigned null, leading to NPE b) At line 162, last could be null, leading to NPE c) At line 162, p could be null, leading to NPE d) At line 157, result could be undefined, an error e) At line 162, result could be undefined, an error f) At line 153, p could be null leading to NPE g) At line 154, last could be null, leading to NPE

2-Suppose a static method has a parameter l of type Location and a parameter frac of type double, and a local variable x of type double. Which of the folowing statements will cause a side-effect that could be observed by the caller? a) return new Location(10,20); b) l.shift(10.0,20.0); c) l = l.clone(); d) x = distance(l,new Location(0,0)); e) l = new Location(3,4); f) x += 10.0; g) System.out.println(l.getX());

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image_2

Step: 3

blur-text-image_3

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Database Administration The Complete Guide To Dba Practices And Procedures

Authors: Craig S. Mullins

2nd Edition

0321822943, 978-0321822949

More Books

Students also viewed these Databases questions