Rama Kumar PV

Greenhorn
+ Follow
since Dec 26, 2003
Merit badge: grant badges
For More
Cows and Likes
Cows
Total received
In last 30 days
0
Forums and Threads

Recent posts by Rama Kumar PV

It's going to print the value equivalent to ascii "1" at console. Ascii 97 is 'a' and Ascii 98 is 'b'. So, 'b' - 'a' results in integer 1. As 'b' - 'a' is a compile time constant,

is valid and allowed. If you change the print statement to

You will get to know the Ascii number that is being printed.
Cheers,
Rama
As Exception is valid class, you can return an instance of it back to the caller and can throw the exception in the caller.
See code below..

Cheers,
Rama
Sridhar,
You can refer to both static and non-static members from within a non-static method but not the other way round. That's why your piece of code compiled fine..
Cheers,
Rama
Sridhar,
Both
System.out.println (an.numberOfLegs);
and
System.out.println (this.numberofLegs);
will equally work fine(Because, you can directly access the protected member variable either with the instance variable or thru inheritance). It didn't work in your code because, of case-sensitive nature of Java. If you check the initial post by Ngozi, above he is printing back "an.numberofLegs" and not "an.numberOfLegs".

Cheers,
Rama
Sridhar,
Please insert your code sample using the CODE button option in Instant UBB Code.
Your code sample gives 2 as the output as you thought, because of the definition of the anonymous array,
int anar[]=new int[]{1,2,3};
You need not give the size of the array using the above array definition format. As the array index starts from 0, anar[1] will print out 2.
Cheers,
Rama
[ February 03, 2004: Message edited by: Rama Kumar PV ]
Java clearly specifies the number of bytes any predefined datatype can take with the exception of boolean, whose storage will be virtual machine dependent, which is of no importance to the developer. The bit depth of a boolean type will not be asked in the exam. Hope this helps..
Cheers,
Rama
Vineela,
The reference variable P2 is not pointing any where as it is null. You cannot invoke methods on a null pointed reference variable as it will lead to NullPointerException as you got in this case.
Cheers,
Rama
Gayatri,
The if statement and the switch statement are decision making controls and are not loops. So, the enclosing loop for your switch construct will be the "do..while" loop.
Cheers,
Rama
The break statement for case 2 will take you out of both switch and the "do..while" loop and hence the result..(break will always take you out of the enclosing loop unless a label is mentioned after break).
Rama
How can an interface implement another interface?
An interface may extend one or more interfaces but is not eligible to implement any interface(s). All interface implementations has to go into a class. Hope this helps.
Rama
[ January 22, 2004: Message edited by: Rama Kumar PV ]
It is just like any other error/exception and is not related to enabling or disabling of assertions. Enabling/Disabling of assertions will affect only those lines having the assert keyword followed by a boolean expression.
Rama
You can safely mention the generic Exception class in the catch block even though no exception was thrown in the try block.
Rama
You cannot club the declaration of one variable type with that of other without an explicit statement statement delimitter ";" in between.
Here, "," can be used only for sequential execution. Say, in a for loop, incrementing a set of counters or in a declaration of a set of variables of a single type.. e.t.c.
In the above piece of code, if you replace
int []a3, int[] a4;
with
int []a3; int[] a4;
or
int []a3, a4;
it will work fine.
Cheers,
Rama
An object can be categorized as mutable if it can be changed internally (through the usage of methods).
Here, Math class cannot be instantiated and hence all it's methods are static. All wrapper classes are immutable along with String. StringBuffer represents mutable strings. So, possible answers can be, java.lang.Boolean and java.util.String and not StringBuffer.
Cheers,
Rama
Dhana,
If you shift a char, byte, or short, it will be promoted to int before the
shift takes place, and the result will be an int.
Try changing the code to
byte i =-128;
System.out.println(i<<=1);
to get the value of 0.