• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Tim Cooke
  • paul wheaton
  • Paul Clapham
  • Ron McLeod
Sheriffs:
  • Jeanne Boyarsky
  • Liutauras Vilda
Saloon Keepers:
  • Tim Holloway
  • Carey Brown
  • Roland Mueller
  • Piet Souris
Bartenders:

"Language Fundamentals" Questions

 
Ranch Hand
Posts: 231
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Hi everybody,

Q1)What happens if you try to compile code that looks like this.
Class MyString extends String{ }
a] The code compiles successfully
b] The code does not compile because you have not defined a main( ) method
c] The code does not compile because String is abstract
d] The code does not compile because String is final
Q2)Which of the following is the correct form of declaration of package and classes?
a] package p1;
package p2;
import java.awt.*;
class Hello{ }
b] package p1;
public class Hello{ }
import java.awt.*;
c] package p1;
import java.awt.*;
class Hello{ }
public class Sample{ }
d] import java.awt.*;
//This is the comment
class Hello
Q3)Which color is used to indicate the class method in standard�java doc�format documentation
a] red
b] green
c] yellow
d] blue

Q4)Which of the following main method in java application is correct?
a] public static main(String args[])
b] static public void main(String []a)
c] private static void main(String args[])
d] public void static main(String args[])
e] public static void main(String)
f] static void main(String args[])

Answer given : b,c,f.

Q5)To restrict access to a static member to the class itself,
a] use the final keyword
b] use the private keyword
c] do not use a keyword at all for the member
d] a static member cannot be restricted in this way

Answer given : b.
Q6) Which of the following integer primitive can correctly represent a value of 65535?
a] int
b] char
c] short
d] long

Answer given : a,d.

Q7)Which of the following variable names are invalid?
a] integer
b] %cd
c] $ind
d] 4exam
e] ja-va

Answer given : b,d.
Q8)Which of the following statement is false?
a] An instance method can be both protected and abstract
b] A static variable can also be final
c] A static method can also be protected
d] A static method can also be abstract

Answer given : d.

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
a] green
b] yellow
c] The code does not compile
d] The code throws exception at runtime

Answer given : d.

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.

Q11)Anonymous arrays can be created.
a] True
b] False
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.
 
Ranch Hand
Posts: 31
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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).]
 
Ranch Hand
Posts: 59
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hello,
Q3)Which color is used to indicate the class method in standard�java doc�format documentation
a] red
b] green
c] yellow
d] blue
A3) blue...but not sure.
Q4)Which of the following main method in java application is correct?
a] public static main(String args[])
b] static public void main(String []a)
c] private static void main(String args[])
d] public void static main(String args[])
e] public static void main(String)
f] static void main(String args[])
Answer given : b,c,f.
A4)b,c,f .... will compile and run without any error.
Q6) Which of the following integer primitive can correctly represent a value of 65535?
a] int
b] char
c] short
d] long
Answer given : a,d.
A6) Answer should have been a,b,d...as char also correctly represent a vlaue of 65535 ....that is '?'
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.
A10)b ,d
d : to convert int(-1) to char, casting to char is required.
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.
A12)a .....As main method can be overloaded but it is also true that, command line arguments will accept String format and can be declared as final.
If i am wrong please let me know.
Thanks.

[This message has been edited by Mukti Bajaj (edited January 08, 2001).]
 
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
---------------------------------------------------------------
Q3)Which color is used to indicate the class method in standard�java doc�format documentation
a] red
b] green
c] yellow
d] blue
A3) blue...but not sure.
-----------------------------------------------------------------
Hello Mukti you are right
Javadoc is common javatool like as javac,java . It generates java documents in HTML format. I mean API in HTML form.There are many options keys which do various function along with javadoc.
So go to API and see ,in what color the class methods are. It is blue.
------------------------
For sasi & mukti

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
Answer.
Only int & long can hold 65535. short can't hold as it is 16 bit and its range is between -32768 to 32767.
And when it comes to char type it can hold values only in "unicode character format".That means it hold characters in the range from \u0000 to \uffff. Then How come the number 65535 fits in it.It doesn't .( Moreover a char's size is 16 bit )

---------------------------------------------------------------
For Sasi
Q11)Anonymous arrays can be created.
a] True
b] False
I guess it is false
Can some one give more explanation
Answer
yes.Anonymous Arrays can be created . The reason being Arrays are composite Datatype holders like classes. & unlike conventional dataholders/datatypes (int,long,float,boolean etc...).
We can put any type of information like as Unicode characters,integer(signed),ieee754 & boolean one's in to an array,In which various data type initialze to their default values.0 in the case of int,\u0000 for chars,false for boolean.
So with out certainity,they can be created
My answer is arrays can be anonymous.Suggestions accepted.


 
Ranch Hand
Posts: 39
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi all,
These are my answers to some of the contraversial ques discussed abouve:
Q.6
COMPILE AND RUN THIS:
public class Test{
public static void main(String args[]){
char c = Character.MAX_VALUE;
System.out.println((int)c);
}
}
OUTPUT:
65535
So, char can hold 65535. (\uffff)
Q.7
answer is b,d,and also e.
ja-va is also a invalid variable name.
Q.9
The only reason i think there can be a compile-time error here is because of the main() function with a capital M. Otherwise the argument 2 is not out of bounds.
Q.12
b is right choice.
You can overload main() as many times you like. At runtime, JVM looks for the main() with the required signature, i.e. with String[] as argument.
And main() can also be declared final.

Hope this helps. always open for contradictions.
-Aj.
 
amit sanghai
Ranch Hand
Posts: 231
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Hi all,
Thanks to all of you who took considerable time and effort to answer 12 questions at a time. From now onwards I will post 1 or 2 questions in one post.
Answers to controversial questions :

Q3) The answer given is green.

Q5) What is its exact meaning? I thought it was to restrict access to the static variable so that it is not accessible to the class in which it is defined. But I suppose that is ridiculous!!!
Q6) I personally think that char datatype can hold value of 65535.
Q7) i personally think that e) is also invalid.
Q8) I do not understand why abstract and static methods cant be defined in the subclass?
Q9) I think it should compile.
Q10) What about choice (c).
 
amit sanghai
Ranch Hand
Posts: 231
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Hi all,
Thanks to all of you who took considerable time and effort to answer 12 questions at a time. From now onwards I will post 1 or 2 questions in one post.
Answers to controversial questions :

Q3) The answer given is green.

Q5) What is its exact meaning? I thought it was to restrict access to the static variable so that it is not accessible to the class in which it is defined. But I suppose that is ridiculous!!!
Q6) I personally think that char datatype can hold value of 65535.
Q7) i personally think that e) is also invalid.
Q8) I do not understand why abstract and static methods cant be defined in the subclass?
Q9) I think it should compile.
Q10) What about choice (c).
 
Ranch Hand
Posts: 130
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Q9. Catchy..
Main --> 'm' is in caps.
so the JVM will shout can't find main method!! runtime exception.

Q10. choice c is correct.
 
Greenhorn
Posts: 12
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Q3)Which color is used to indicate the class method in standard�java doc�format documentation
a] red
b] green
c] yellow
d] blue
It would be whatever your browser defaults as visited links, since each class method's name is surrounded by tags, and they link to below on the page, ie they are visited links.
 
reply
    Bookmark Topic Watch Topic
  • New Topic