Ashwin Rao

Ranch Hand
+ Follow
since Oct 21, 2014
Merit badge: grant badges
For More
Cows and Likes
Cows
Total received
In last 30 days
0
Forums and Threads

Recent posts by Ashwin Rao

I was reading about slicing a list in python. All was well until I started the next topic that said there was a third parameter to the slicing called as step. I understood that except for why does the code below print the shoppingList in the reverse order. Can anyone help me? Thanks!
9 years ago
Closing the writer first flushes it and then closes it. So I guess it would have worked if I had just flushed it.
9 years ago
I had forgotten to close the writer!!
After I added writer.close() I got the output! Sorry for the trouble!
9 years ago
Hi,
I'm trying to find out the minimum scalar product of a given two vectors. I've succeeded in my attempt to find out the minimum scalar product. I found the question here. I'm trying to solve the small input. My program calculates the minimum scalar product for all 1000 cases but is only writing 845 of them to the file. I don't understand what's the problem. I think it may have something to do with FileWriter. Any help is much appreciated.
My code is given below:
9 years ago
Consider the code below:


Now in main if you write:


Even before you execute the program the compiler knows which method within the class is gonna be called. Hence the JVM does not have anything to decide at run-time. It already knows which method has to be called based on the arguments. I don't think you can call this compile time binding because the TestClass object is not created until and unless you "run" the program. Whenever you think about something related to objects think "run-time" whenever something is related to static stuff think "compile-time".
9 years ago
Also I want to add one more thing.. a class cannot be marked private. A class can only be marked public,abstract or final.
9 years ago
I think you're confusing Java with C# or C++. Java does not offer operator overloading i.e you cannot define the way operators work on different types.
static functions exist before any objects are created. So you can call a static method before you create any objects of that class as shown below:


However you need to remember that static methods behave differently than instance methods when involved with inheritance and polymorphism:



Now inside main if you write something like this:
It would print "Inside SuperClass" instead of "Inside SubcCass". Static methods are not involved in polymorphism!
Hope this helped!!
9 years ago
Here you create an array: Dog[] myDogs = new Dog[3];
Arrays have some built-in superpowers!
"length" is one of them. This "length" variable stores the max. length of the array. In this case it stores 3.

9 years ago
Here's what I think: You need to create a new Person object every time you loop through your while() loop in the main function. To that new object you have to set the name and id fields and then add that object to the list. That way you have a list of Person objects for your list.
9 years ago
Here's what I think is happening. Correct me if I'm wrong:

When you call tst.addAll(); count is incremented by 1 and control goes to the super class version of addAll() as is specified by super.addAll(); but inside the addAll() method of the superclass when you call the add() method it actually calls the overridden add() method in the subclass because the object through which we called it was a subtype.

Am I right? :|
9 years ago
And what CB means by transient sum is that you don't actually need to store the sum of A and B in a seperate variable. You can do something like this return (a + b);
Also the variables A and B inside the main() method have NO RELATIONSHIP to the variables named A and B inside AddAandB. Setting A inside main() does not set A in AddAandB. The two are different. You need to set the A and B inside AddAandB for your program to work. To set them you can pass values through the constructor: setSumAandB(double NumberA, double NumberB).
Hope I helped you out!
9 years ago
Inside the api folder I do not have index.html I have the following folders:

java
javax
org
resources
9 years ago
I actually did download the Java API docs but I don't have a clue how to use them offline..I always end up going to the online docs. Can anyone please explain to me how to use the offline docs?
Thanks!
9 years ago
There is no passage. It written as just one sentence or point and it goes like this:

Only static variables and methods can be accessed as part of the call to super() or this().(Example:super(Animal.NAME) is OK, because NAME is declared as a static variable)

9 years ago
I'm preparing for the OCA 7 exam. I learnt from the OCA 7 book by K&B that you are only allowed to access static variables and methods as a part of the call to super() or this(). I think I would find it easier to understand if they had given a complete example but they just gave (super(Animal.NAME); // OK because NAME is static.) but I am not finding the complete code in the book. So if anyone could give a complete example I would be really grateful. Also another query..Is this actually used in real-world programs?
9 years ago