# Manish Pamnani

Ranch Hand
since Jan 30, 2018
Cows and Likes
Cows
0
In last 30 days
0
Total given
0
Likes
1
0
Total given
28
Given in last 30 days
0
Scavenger Hunt
Ranch Hand Scavenger Hunt
Greenhorn Scavenger Hunt

## Recent posts by Manish Pamnani

Hey,

I am solving a problem on hackerrank(https://www.hackerrank.com/challenges/compare-the-triplets/problem?h_r=next-challenge&h_v=zen). The problem states to complete the function
compareTriplets which must return an array of two integers, the first being ALice's score and the secoond being Bob's.

compareTriplets has the following parameter(s):

a: an array of integers representing Alice's challenge rating
b: an array of integers representing Bob's challenge rating

For more detail on the problem, refer to the following link:
https://www.hackerrank.com/challenges/compare-the-triplets/problem?h_r=next-challenge&h_v=zen

For the same challenge i wrote the following solution:

The problem states that the output should be like [1,1] i.e. [points earned by alice, points earned by bob]

But somehow it displays a array with four elements with the values [1], [], [1], []
Refer to https://ibb.co/GCkwM9j for further details.

Can anybody suggest anything?
2 years ago
Can't switch have a range as a case just like we do in if?

Like for example we can do if(i > 5 && i < 1)

can we do similiar things in switch?

If yes, then how?
3 years ago
Why i am getting the following error :-
Sample2.java:13: error: non-static variable x cannot be referenced from a static context
System.out.println("x in main: " + x);
^
Sample2.java:14: error: non-static variable y cannot be referenced from a static context
System.out.println("y in main: " + y);
^
2 errors

My code is:-

Is it related to the scope of the variable? If it is then 'x' & 'y' must have the scope till the main method!
3 years ago

Emma Vande-Wouwer wrote:Thank you for your reply, here is my command copy pasted :

"Microsoft Windows [Version 10.0.17134.228]

C:\Users\emmav>dir "c:\users\emmav\documents\csi\"
Volume in drive C is OS
Volume Serial Number is 7E29-1FBC

Directory of c:\users\emmav\documents\csi

02/09/2018  13:38    <DIR>          .
02/09/2018  13:38    <DIR>          ..
02/09/2018  13:38               426 HelloWorld.class
02/09/2018  13:33               117 HelloWorld.java
2 File(s)            543 bytes
2 Dir(s)  57.900.068.864 bytes free

C:\Users\emmav>java HelloWorld
Error: Could not find or load main class HelloWorld

C:\Users\emmav> "

Seems like your current directory is "C:\Users\emmav" and you are trying to execute in the directory "c:\users\emmav\documents\csi"  .
Please make sure to navigate to the proper path where your file exists and then execute the file.

and

java HelloWorld.class is a wrong way of executing a java file

java HelloWorld
3 years ago
In the attachement below it says:-

An abstract method has no body!

Why an abstract method has no body & why does it ends with a semicolon?

while a abstract class has an body and we use keyword extends ?
3 years ago
In the image below it says :-
With AN abstract class , the guys doing the work at runtime are instances of a subclass of your abstract class?

What does it means?

Can anyone give me a working example of this?
3 years ago
3 years ago
3 years ago
What is garbage collectible heap & what it is used for?

Why do Objects live on heap & not variables & reference variables?

What's its use?

Can Objects exists without heap?
3 years ago
You didn't initialized variable "height2" outside the scope of "do while" loop
rather you initialized "height2" inside "do while" loop which made it a local variable instead of global variable.
You should initialize "height2" at the beginning of "do while" loop.

3 years ago

SO it means i can inherit any number of subclasses from superclass?
Will there be no affect on running time of my program as it would have so many classes?
3 years ago

Manish Pamnani wrote:. . . but i couldn't figure out a way to make the "atmBalance" variable static so that it could be shared among all objects of ATM we create?

I tried the following methods to make atmBalance static :-
a) Changed int AmtWithdrawn to int AmtWithdrawn = 20000;
b) Changed int AmtWithdrawn to public int AmtWithdrawn
but couldn't get the results.
3 years ago

Ganesh Patekar wrote:

Manish Pamnani wrote:

We know field userName of object referred by one is set to "Manish" so prints Manish but you haven't set any values to other fields of object referred by one hence If you try to print any other fields of this object by invoking getter method on reference variable one like both prints 0 since we haven't set any values to these variables so they have default value 0 because atmBalance and atmPin are of int type.

Each object have their own fields so you have to set them by invoking appropriate setter methods, to get values invoke getter methods and other method too like miniStatement and cash too on every object you create.

As Carey Brown suggested It's good to use constructor to initialize these fields and use toString method to print output.

If you haven't understood yet please go through The Java™ Tutorials: What Is an Object and What Is a Class?

Here is the code i updated as per your suggestions:

1)I also assigned values to every field of the object.
2)I also used this keyword to call the current object instead of using getters and setters(which made my life a lot easier)
3)I changed the method names into camel case as per naming conventions.

but i couldn't figure out a way to make the atmBalance static so that it could be shared among all objects of ATM we create?
3 years ago
I was trying out an example of polymorphism with the following code:-

But here i noticed when we run the code the output is :-

java Splendor
running safely with 60km
running
running safely with 60km

So my question is when Bike b = new Splendor(); & Splendor d = new Splendor(); give the same output i.e. "running" then what is the need to upcasting the reference variable 'b' ?

and what does it helps in?

Regards,
MANISH
3 years ago
Thank you!
3 years ago