Hi,
Q1)What happens if you try to compile code that looks like this.
Class MyString extends String{ }
String being a final class It cannot be subclassed so d is the
answer.
Q2)Which of the following is the correct form of declaration of package and classes?
C is the answer. This is the order 1.Package declarations 2.
import statements 3. class declarations and definitions. The above declarations must occur in the same order even if one or two of them is missing. The answer d in correct order but the class declaration is missing { braces.
Q3)Which color is used to indicate the class method in standard?java
doc?format documentation
I too want to know the answer to this question.
Q4)Which of the following main method in java application is correct?
Answer b public and static can occur in any order.
code with c would compile but we cannot execute the main method as it is declared private.
similarly answer f is also correct but it generates run time error as the access is default and not coderanch.
so b,c,f are correct for compilation purposes
Answer given : b,c,f.
Q5)To restrict access to a static member to the class itself,
Answer given : b.
Answer b is true as the private members are the most restrictive and cannot be accessed outside the class methods to which they belong.
Q6) Which of the following integer primitive can correctly represent a value of 65535?
Answer given : a,d.
An int and a long variables each being represented by 32 bits and 64 bits respectively can each store the value 65535. in short( 16 bits )the first bit represents the sign bit hence we cannot store this val in a short variable. But I am doubtful about the answer b in fact a char being a 16 bit val it must represent this
val 65535. Any body help me in thie regard.
Q7)Which of the following variable names are invalid?
declarations integer and $ind are O.K ( as integer is not a keyword but int and Integer are. ) a dollor sign can precede a var name.
This leaves b ( a % sign cannot be the first letter or any where in a var)
e even this is wrong unless it is written as ja_va. ja-va is an invalid declaration as minus sign cannot occur in a declaration.
So Why not even choice e
Answer given : b,d.
Q8)Which of the following statement is false?
Answer given : d.
Answer d is correct because an abstract method needs implementation in its sub class but if it declared as static too it must be defined in the class it is being declared. be cause of this conflicting requirements d is correct answer.
Q9)Consider the following code
public static void Main(String args[]){
System.out.println(args[2]);}
The above is executed by the following command line
java test blue green yellow
What would be the output
Answer given : d.
The code compiles because what ever is the definition of a class as long as it follows the requirements given on the Q1 above. But it fails at runtime as there is no method of the name main the above method name is declared as Main .
Q10)Which of the following are invalid?
a] char \u0062 = ?b?;
b] char c = ?caf�?;
c] ch\u0061r a=?a?;
d] char c = -1;
Answer given : b,d.
b is incorrect because a char variable cannot store a string
and even the representation 'cafe' is incorrect.
I have a doubt on d : char variables cannot store negative values.
Q11)Anonymous arrays can be created.
a] True
b] False
I guess it is false
Can some one give more explanation?
Q12)True or False
main method can be overloaded
main method cannot be final
a] true
true
b] true
false
c] false
false
Answer given : b.[/B]
I say c is correct How b is correct main cannot be overloaded as
it takes the command line arguments in String format. It can be final .
[This message has been edited by sasi dhulipala (edited January 08, 2001).]