Originally posted by Rajpal Kandhari:
Helo Krishna ,
can anyone explain why we cannot write a class as protected?
Who say that we can not write a class as protected. "Java is a funny Language as English."
Have you ever worked with a source code that fails to compile but when you try to run it works just fine. Well this
thing just happen in Java. Check the following code.
protected class Test {
public void SomeMethod (){
System.out.println("Checking if it is working with protected");
}
public static void main (String args[]){
Test obj = new Test();
obj.SomeMethod();
}
}
when you try to compile it will give you compile error saying somthing like class or interface expected.
But on the other hand when you will check you'r directory where you have stored the Test.java file you will see
Test.class file. And now try to run this Test file. It will give you desired output. And this thing will
work with private, static and any combination of access modifiers.
But as the API says that top level class can only be either public or friendly ("default"). And this is the bottom line
Regards,
Raj.--.
Originally posted by Sean MacLean:
[B]Preeti,
Since this looks an aweful lot like a question in the JavaRanch CattleDrive, I'll only give you bits of the code to do this. So here it goes. There is no built in facility in Java to do this type of conversion. You have to do it by 'hand'. The simplest way is to use the / division and % (mod) operators to determine the rank of the numbers. For instance,
int deci = 22 / 10; // equals 2 because it's integer division
and then
int uni = 22 % 10; // equals 2 because that's the remainder
Now set up two arrays like this,
and get the String representation as such,
String result = deciStrings[deci] + "-" + uniStrings[uni+1];
Of course, you have to derive the logic to make this handle any number. Hope this helps.
Sean[/B]