• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Ron McLeod
  • Paul Clapham
  • Bear Bibeault
  • Junilu Lacar
Sheriffs:
  • Jeanne Boyarsky
  • Tim Cooke
  • Henry Wong
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • salvin francis
  • Frits Walraven
Bartenders:
  • Scott Selikoff
  • Piet Souris
  • Carey Brown

Whiz lab Prep kit PRoblems

 
Ranch Hand
Posts: 634
Eclipse IDE Chrome Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Whiz lab Prep kit



what can be the answers to these questions


Q1.
i think answer should be
A

Q2.
i think answer should be
A
B

Capture.PNG
[Thumbnail for Capture.PNG]
3.png
[Thumbnail for 3.png]
 
Ranch Hand
Posts: 2066
IntelliJ IDE Clojure Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
mohitkumar gupta, could you please hard-code the question? Otherwise, it'll not readable!
 
Mohit G Gupta
Ranch Hand
Posts: 634
Eclipse IDE Chrome Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
i request all users to please download the image files to see the Question
It's quite clear in the image
 
Mohit G Gupta
Ranch Hand
Posts: 634
Eclipse IDE Chrome Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
i request all users to please download the image files to see the Question
It's quite clear in the image
 
Abimaran Kugathasan
Ranch Hand
Posts: 2066
IntelliJ IDE Clojure Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

mohitkumar gupta wrote: i request all users to please download the image files to see the Question
It's quite clear in the image


Have a look on => PostTextNotScreenshots And ShowSomeEffort!
 
Mohit G Gupta
Ranch Hand
Posts: 634
Eclipse IDE Chrome Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Q1.
you have a hashmap whose keys need to to be retrieved in a sorted manner.Which of the following would help you achieve this?
Select any 2 options
a.copy contents of hashmap to treemap
b.add keys of hashmap to treeset
c.pass the hashmap to Arrays.sort method
d.pass the hashmap to Collections.sort method

i think answer should be a and b
please,tell if i am wrong and do give the right answer with reason
Q2.

What's the output of the following if assertions are enabled ??(Choose ONe)



a.compiles and run
b.compiles an throws AssertionError with message ut of range
c.compilation error at line 7
d.compilation error at line 14

i think answer should be b
please,tell if i am wrong and do give the right answer with reason
 
Abimaran Kugathasan
Ranch Hand
Posts: 2066
IntelliJ IDE Clojure Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

mohitkumar gupta wrote:Q1.
you have a hashmap whose keys need to to be retrieved in a sorted manner.Which of the following would help you achieve this?
Select any 2 options
a.copy contents of hashmap to treemap
b.add keys of hashmap to treeset
c.pass the hashmap to Arrays.sort method
d.pass the hashmap to Collections.sort method

i think answer should be a and b


Did you check those APIs? Do they take HashMap as arguments?
 
Mohit G Gupta
Ranch Hand
Posts: 634
Eclipse IDE Chrome Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Whiz LAb PrepKit


Q3.

Which of the following statement are true??(CHoose one only)

a.The code implements the hashCode correctly
b.The code doesnot implements the hashCode correctly
c.Implements of the hashCode correct if only if equals is not overriden
d.The given code doesnot contain enough information to comment about implementation of hashCode
e.none of these

i think answer is a
because
i would have different value each time so hashCode returned would be different for each object of class A

please,tell if i am wrong and do give the right answer with reason

 
Ranch Hand
Posts: 155
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

mohitkumar gupta wrote:
Which of the following statement are true??(CHoose one only)

a.The code implements the hashCode correctly
b.The code doesnot implements the hashCode correctly
c.Implements of the hashCode correct if only if equals is not overriden
d.The given code doesnot contain enough information to comment about implementation of hashCode
e.none of these



The correct answer should be b
The hashValue returned by method hashCode() identifies the bucket in which the item is hashed. This makes searching easier, where you visit the bucket using the hashCode first, and then search for the element in the bucket.



The above code uses a random number, and is inconsistent when called on the same item twice.
Write some test code and try it.
 
Trivikram Kamat
Ranch Hand
Posts: 155
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Following Code uses random number in generating hashValue, and prints false although Set contains the element.



It will print true if you compile and run after commenting the method hashCode()
 
Your mother is a hamster and your father smells of tiny ads!
Building a Better World in your Backyard by Paul Wheaton and Shawn Klassen-Koop
https://coderanch.com/wiki/718759/books/Building-World-Backyard-Paul-Wheaton
    Bookmark Topic Watch Topic
  • New Topic