Priyanka Leo

Ranch Hand
+ Follow
since Sep 14, 2020
Cows and Likes
Cows
Total received
0
In last 30 days
0
Total given
0
Likes
Total received
0
Received in last 30 days
0
Total given
4
Given in last 30 days
0
Forums and Threads
Scavenger Hunt
expand Ranch Hand Scavenger Hunt
expand Greenhorn Scavenger Hunt

Recent posts by Priyanka Leo

Guys,

in the below program i understand that the processing starts from the right side
so in the first accept method 5 is printed and incremented to 6.
and the  andthen method is suppose to print 6. However the output that i get is 56.
Can someone please clarify.

Thanks in Advance!!
Guys

I am aware that consumer takes a parameter and does not return anything !!

But the below two programs are quite confusing for me Can someone please help me understand the same.

This is the first program!
According to the explanation : printNames does not take any argument But the argument for forEach method requires a method that takes an argument and hence this doesn't compile




The below is the second program. Even in this program inside forEach a method that doesnt take any parameter is used but this doent throw any compiler error. Can someone please explain the difference.

I am not sure what i am missing here!!.

What will the following code print when compiled and run?

List<Student> slist = Arrays.asList(new Student("S1", 40), new Student("S2", 35), new Student("S3", 30));
Consumer<Student> increaseMarks = s->s.addMarks(10);
slist.forEach(increaseMarks);
slist.stream().forEach(Student::debug);

Thanks !!!



Hello Guys Given the below code and the choice of answers are :
a.process(fnames, t::eat);
b.process(fnames, t::calories);
c.process(fnames, TestClass::size);
d.process(fnames, Carnivore::calories);
e.process(fnames, Tiger::eat);

Out of which the correct answers are a,b,c

I understand that a and b are correct but i cannot understand why c is correct. as TestClass is no way related to the carnivores class. Can someone please help me understand the same.

Thanks in advance!!

Dears,

I was practcing for the OCP test and came across the below code. As per my understanding the answer that i assumed was 11 but the actual answer is 10. Can someone please help me undrerstand this piece of code.

Thanks in advance!!
Guys i was asked the below question:

How to increase the performance of the following code:



Could you please help me with the solution for this ..
1 month ago
I was doing the practice test in enthuware and came across the below question. The answer for the same is any number from -5 to 3. Can you please help me understand the same.

What are all possible values this program can print when run?

Thanks in advance!!
Hello guys,

the below code throws compiler error because of line 11. But i assumed that since e is null it wont be handled and it produces no output. Can someone please help me understand the logic behind this program.
Thanks in advance!!

Hi Guys,

I was practicing unbounded wildcard. I tried the below program and i am getting the error as follows.



Error:
LogHelper.java:23: error: no suitable method found for add(Integer)
n.add(new Integer(5));
^
   method Collection.add(CAP#1) is not applicable
     (argument mismatch; Integer cannot be converted to CAP#1)
   method List.add(CAP#1) is not applicable
     (argument mismatch; Integer cannot be converted to CAP#1)
 where CAP#1 is a fresh type-variable:
   CAP#1 extends Object from capture of ?
Note: Some messages have been simplified; recompile with -Xdiags:verbose to get full output
1 error

But i tried the same with the below program by passing the list to a method that uses wildcard and its working.  Can you please help me understand the same.



Thanks in advance!!!
I assume the answer was Book.java will be copied but the answer for the same is Exception is Thrown. Can you please help me understand this program. Thanks in advance


Below is the directory structure for F:

F:.
└───A
   └───B
       └───C
               Book.java


Given code of Test.java file:

Dears,

I was trying out the review question from the OCP book by Jean. I came across the following code.





A.It compiles and runs without issue, outputting the total length of all strings in the
stream.
B. The code will not compile because of line q1.
C. The code will not compile because of line q2.
D. The code will not compile because of line q3.
E. It compiles but throws an exception at runtime.

I assumed that the answer for this was option e. But the correct answer is Option c.

Explaination from the book:  C. The code does not compile, so A and E are incorrect. The problem here is that c1 is a
String but c2 is an int, so the code fails to combine on line q2, since calling length() on
an int is not allowed, and C is correct. The rest of the lines compile without issue. Note
that calling parallel() on an already parallel is allowed, and it may in fact return the
same object.

Can someone help me understand this please.
Guys,

I understand that by using lower Bounds that we can use the superclass as well as the class that we specify. But unfortunately i cannot understand the following example given in the OCP book




According to what they have explained is that i assume this is same output that we can expect if we use extends.

Can someone please help me understand this.

Thank you!!!
i interchanged and tried i am still facing the same issue
Hello Guys!!,

I am not able to compile the below code because of this error. (I am using JDk and JRE 8)

C:\javafiles>javac LogHelper.java
LogHelper.java:3: error: package java.nio.files does not exist
import java.nio.files.*;

Could you please help me resolve this issue.



Thanks guys!!
Hi Guys i was practicing Lambda expression where i came across the below piece of code :

my doubt here is that we have created a supplier that contains arrayList
how can we add eleents to the below List? Can you please help me understand the same



Thankyou!!!