Skip to content

Tag: methods

Java, my own copy() method would not work

I am learning java and came upon a small problem, my copy() method will not work. I work based on a UML diagram and I am pretty sure that I’m doing everything correctly. Here is the code: Constructor: copy() method: The error flashes at the parantheses FileName() it says: ‘FileName(java.lang.String, java.lang.String)’ in ‘Exam_Practice_4.FileName’ cannot be applied to ‘()’ Here is

Need help understanding basic recursion problem

I have just started practicing with recursion I have this very simple practice program problem. There are bunnies standing in a line, numbered 1,2,3… The odd bunnies (1,2,3..) have normal 2 ears. The even bunnies (2,4,6…) have 3 ears, because they each have a raised foot. Recursively return the number of ears in the bunny line. I have the solution.

How to call a method twice in a row?

I have a code where in my class I would like to be able to call the method answer twice like qns.answer(5).answer(7). But right now when I call the method answer as below, I get the error cannot find symbol. For example: Would appreciate if you could kindly give some pointers on how to get around this. Answer Question can

Implementation of invokevirtual in JVM

I had expected that the Java Virtual Machine would use a simple lookup table for normal method invocations: The object contains a pointer to a lookup table with the addresses for all methods that the class implements (including the methods implemented by super-classes). A specific method is simply represented by an index into that table. The JVM looks up the