milind k das

Greenhorn
+ Follow
since Sep 29, 2019
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
8
Given in last 30 days
8
Forums and Threads
Scavenger Hunt
expand Ranch Hand Scavenger Hunt
expand Greenhorn Scavenger Hunt

Recent posts by milind k das

Thank you very much for response. I have another question.

We have Array which can store object of a class type.

for example: City[] cities = new City[10]; on a City class.

And arraylist is. ArrayList<City> cities = new ArrayList<>(); While arraylist initiates size at 0.

Why is separate ArrayList needed while Arrays themselves can work well? And what is need for conversion of Arrays to ArrayList and ArrayList to Array using Collections class? I don't know nothing about collections or generics yet. Please explain in simple terms.
4 days ago


In this program, System.out.println(list); statement is printing the elements's values in list. My question is, isn't list a reference variable to ArrayList? Is it not supposed to print reference value of "list"?
4 days ago

Stephan van Hulst wrote:Don't use floating point values for anything other than imprecise measurements. Your account balance should be an integer and your interest rate either an integer or a BigDecimal.

IDs should be strings, not integers.

Make the ID and creation time of an account final.

Make all methods that are not intended to be overridden final. When in doubt, make it final.

Perform parameter validation in your mutators. You should not be able to withdraw or deposit negative amounts. Also, check for integer overflows.

Validate class invariants by throwing exceptions. When you try to withdraw more than the overdraft limit allows, throw an exception.

Don't use long sequences of string concatenations. Use a formatter instead.



Thank you very much. this has been helpful.
4 days ago



In this program, System.out.println(list); statement is printing the elements's values in list. My question is, isn't list a reference variable to ArrayList? Is it not supposed to print reference value of "list"?
4 days ago

Carey Brown wrote:Typo error. Check your method names.


ooops!! Thank you very much!
1 week ago


In the above code, I have Account class in different Package - Chapter9 and class CheckingAccount is in package Chapter11. I have imported the Account and all methods in Account are public. However, in class CheckingAccount, even though the withdraw method I want to override has same signature, @Override is showing error "Method does not override method from its superclass". Please let me know why its not letting me override? What's wrong here?
1 week ago
@Stephan van Hulst Thank you for explanation. Your explanation gave me some clarity. Still confused. But I will reading again this topic more detail. Please such some source with explanation in detail including how JVM handles.

@Campbell Ritchie Thank you for posting that. I was about to post my second question on this. Can you elaborate on this why it's not applied on data fields and static methods? Thank you
1 week ago
Hello I started reading a java book. Introduction to Java programming by liang. I have question in polymorphism section of the book. Below are the statements from the book.

An object of a subclass can be used wherever its superclass object is
used. This is commonly known as polymorphism (from a Greek word meaning “many
forms”). In simple terms, polymorphism means that a variable of a supertype can refer to
a subtype object.

Polymorphism means that a variable of a supertype can refer to a subtype object.




I believe superclass cannot be of subclass type. While subclass can be of superclass type and holds superclass type object too with subclass object.

If this is the case, how can superclass type variable can hold subclass type object? Is it not contradicting? Sorry if its basic, please explain in simple terms

Consider below example:




In the code, may I know what is the difference in two statements,


And how are the objects allocated and their behavior in above two statements.
1 week ago