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

Sridhar Katakam

+ Follow
since Jan 28, 2001
Cows and Likes
Total received
In last 30 days
Total given
Total received
Received in last 30 days
Total given
Given in last 30 days
Forums and Threads
Scavenger Hunt
expand Ranch Hand Scavenger Hunt
expand Greenhorn Scavenger Hunt

Recent posts by Sridhar Katakam

Default is 'package' not 'public'

Originally posted by ricky gonzalez:
I think "private static void main(String [] argv)" is not going to get compiled. Can you post the source code?
Also, static void main(String [] argv) will get compiled and run successfully. I guess all fields are by default public.

20 years ago

Hi all
Consider this question:
Given the following code fragment from a class definition, which of the following statements is true? [Check all correct answers]
1. int Aval = 0x65;
2. byte Bval = 065;
A) The variable Aval has been initialized with a hexadecimal format literal, and Bval has been initialized with an octal format literal.
B) Both Aval and Bval contain 65.
C) The logical test Aval > Bval would evaluate True.
D) The compiler would report a NumberFormatException on line 1.
Answer: Answers A and C are correct. The hexadecimal literal evaluates to 101 decimal, and the octal literal evaluates to 53 decimal. Answer B is incorrect because line 1 uses a hexadecimal literal and line 2 an octal literal. Answer d is spurious because it is the Java runtime that reports exceptions, not the compiler.
Can any one tell me how to convert hexadecimal and Octal literals to decimals ?
like Hexadecimal 0x65 is equivalent to Decimal 101
Octal 065 is equivalent to Decimal 53.
20 years ago

Four Signed integral types: byte, short, int, long
Unsigned integral type: char
Primitive type 'boolean' is unsigned but it doesn't come under 'integral' types.
I am 100 % sure about the above.
Now coming to integer types, I believe what Judy quoted is true that integer types cover byte, short, int and long which are signed. But ValDra wrote indicating that 'char' is a integer type. How is that possible ?

Originally posted by Val Dra:
Question 2: is the declaration " all integer types are signed numbers " true or false? As I know, it is true because all integer types(short, byte, int, long) are signed numbers. If "integral type" is used here instead of "integer type", then it will be wrong since integral type includes char as well. Agree?
No not all integer values are signed , char is unsigned only positive values 0 - 65000 i believe. Although it's still a numeric type.

The question that started this discussion was mentioning 'Access Modifier' and you brought 'static' into the picture. 'Static' is only a modifier not a 'Access Modifier'. Access Modifiers are 'public, protected and private' (I wonder why 'package' (default) isn't mentioned in RHE book).

Originally posted by Sivalingam Sivasuthan:
hi Priya Kannan,
Why Do we need an instantiated OBJECT to access a Static member of that Class?.

Can any one tell me where the errata for the book 'Complete JAVA 2 Certificaton' Study Guide can be found ?
Chapter 1, Page 20, Line 7 (program at the bottom of the page)
reads: changeMe.setLabel("Blue"));
when I think, it should be:
Inputs ?
The whole code works like this:
x gets the value of 6.
x>2 is checked, i.e., 6>2 (evaluates to true);
Before entering the body of the loop, post decrement occurs, i.e., x gets the value of (x-1), i.e., x becomes 5
In the body of the loop, post decrement occurs, i.e., x gets the value of (x-1), i.e., x becomes 4;
'In loop: 4' is printed.
4>2 is checked (true);
x becomes 3.
In the body, x becomes 2;
'In loop: 2' is printed.
2>2 is checked (false); Before coming out of loop, x is decremented, i.e., becomes 1.
(Comes out of the loop) and 'After loop: 1' is printed.
If in the code, x-- is replaced by --x for both it's occurances, the result would still be the same.
My earlier post on this was wrong. I was under the impression that no assignment (i.e., x getting a new value), what so ever will occur in the condition of while loop.
In loop: 5
In loop: 4
In loop: 3
After loop: 3
Is this correct ?

The answer is 1.
A nested class has unlimited access to its enclosing class's members, even if they are declared private. This is because the access specifiers restrict access to members for classes outside of the enclosing class. The nested class is inside of its enclosing class so that it has access to its enclosing class's members.
Definition: An inner class is a nested class whose instance exists within an instance of its enclosing class and has direct access to the instance members of its enclosing instance.