Which one is faster in java ?
for(int i = 100000; i > 0; i--) { }
for(int i = 1; i < 100001; i++) { }
Answer is a)
for(int i = 100000; i > 0; i--)
{
}
Array operations are faster.
Parent method will be invoked first.
static void changePoint ( Point p) {
p.x = 100; p.y=200;
}
static void changePoint(Point p) {
p = new Point(100,200);
}
Answer :
(100,200)
(700,800)
[Note : Primitive type is passed by value in method parameter and objects are passed by value of the reference. In a method if the object values are changed , it will reflect, but if we try to change the reference itself its original reference/object will not change, as only copy of the reference is changed.]
Which one of these primitive types are unsigned?
int
long
char
double
float
c) char (All numeric data types are signed. 'char' is the only unsigned integer type.)
No, inner class cannot have static members.
Yes. [Constructor can throw exception.]
Overriding methods cannot throw more generic exceptions than base method.
Which one of the following is not correct?
x = = Float.NaN
Float.isNan(x);
Myobject .equals(float.NaN);
a) x = = Float.NaN
Yes, finalize method can be overloaded but only the below given version is called by garbage collector : protected void finalize() throws Throwable { };
False. [Nested class can extend any class or implement any interface.]
Yes, we can declare derived class first and then base class in Java.
False. [GC is a low priority thread.]
True, but the most once and not more than that.
Dictionary is a class and not an interface.
Member variables are resolved at compile time.
Map does not implement collection.
Yes the above statement is correct.
What will be output from the following statements :
System.out.println(1+2+”3”);
System.out.println(“1”+2+3);
Answer :
33
123
False [ Random access file descends from object and implements data input and data output.]
No, interface cannot be declared final as they are implicitly abstract.
All methods in an interface are implicitly public, abstract but never static.
False [Java does not support multi-dimensional arrays. It only supports nested arrays.]
No it is not a valid method.
Yes it is a valid method.