Win a copy of Rust Web Development this week in the Other Languages forum!

kawshik java

Greenhorn
+ Follow
since May 30, 2011
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
0
Given in last 30 days
0
Forums and Threads
Scavenger Hunt
expand Ranch Hand Scavenger Hunt
expand Greenhorn Scavenger Hunt

Recent posts by kawshik java

I am not certain if this helps. What I gather is that due to memory effeciency reasons two primitive objects holding values between -128 to 127 will return true when compared using ==.

pradeep rajkumar wrote:Hi,
When i compiled and ran the below code,

I got a Runtime Exception as below,

Its just an ordinary Downcasting right ?
Then why this Exception was thrown ?




You cannot downcast an actual parent object to a child object. The cast will only work if the reference variable is of the parent type but the actual object being referred to is of the child type. So, the acutal object Tree cannot be cast to a child object (Redwood).

Dennis Deems wrote:The answer to all your questions is yes.

There is one extra thing you may be interested to know, which is that an interface can be nested within a class, and in that case it can be declared protected or private. But I do not know whether this is necessary to know for the exam.



Thanks. I haven't yet come across interfaces nested inside a class. Fingers crossed.
Hi all,

I was reading the K&B book and interfaces are said to be implicitly abstract. They can also have two access levels: public and default. My first question is:
Is it correct that interfaces cannot be private or protected?

Secondly, because I see that interfaces can have package access level, does that mean that interfaces can belong to a particular package? So we can add statement to an interface file?

If the answer is yes, interfaces can belong to a package then can we use when an interface wants to extend another interface.

Hopefully the questions are clear and will make sense.

Thanks.

Hama Kamal wrote:

Vijay Tidake wrote:Just a minor correction to statement



Identifier can starts with only $, _ and letters



Identifier can starts with only any currency symbol, _ and letters





Identifiers must start with a letter, a currency character ($), or a connecting
character such as the underscore ( _ ) ,, what other connecting characters are? that is my point?!



Hi as far as I am aware the only connecting character allowed is the underscore (_)
Other such as dot(.) and dash(-) are not regarded as connecting characters in java as they have other meaning.

Seetharaman Venkatasamy wrote:From JLS:



Method invocation conversions specifically do not include the implicit narrowing of integer constants which is part of assignment conversion (§5.2). The designers of the Java programming language felt that including these implicit narrowing conversions would add additional complexity to the overloaded method matching resolution process (§15.12.2). Thus, the example:

class Test {
static int m(byte a, int b) { return a+b; }
static int m(short a, short b) { return a-b; }
public static void main(String[] args) {
System.out.println(m(12, 2)); // compile-time error
}
}

causes a compile-time error because the integer literals 12 and 2 have type int, so neither method m matches under the rules of (§15.12.2). A language that included implicit narrowing of integer constants would need additional rules to resolve cases like this example.



But the implicit conversion works in a return statement. Are there any rules related to implicit conversion in such complex siutations.

Aashu Mahajan wrote:Hi, Prakash Mahto

byte to short -------> Will implicitly cast. It doesn't require explicit casting.
But
short to byte-------->Will Require Explicit Casting



I don't understand how that can be. In the code he was using '5' in both the return value and the method call. I believe both are regarded as integers by the compiler.