Win a copy of Functional Reactive Programming this week in the Other Languages forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Am i correct?

 
Doit
Ranch Hand
Posts: 169
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
1. What would be the result of attempting to compile and run the following piece of code?
public class Test {
static int x; public static void main
(String args[ ])
{System.out.println("Value is " + x);}
}
A.The output "Value is 0" is printed.
B.An object of type NullPointerException is thrown.
C.An "illegal array declaration syntax" compiler error occurs.
D.A "possible reference before assignment" compiler error occurs.
E.An object of type ArrayIndexOutOfBoundsException is thrown.

ANS: A

2. What should you use to position a Button within an application Frame so that the size of the Button is NOT affected by
the Frame size?
A.a FlowLayout
B.a GridLayout
C.the center area of a BorderLayout
D.the East or West area of a BorderLayout
E.the North or South area of a BorderLayout
ANS: A

3. Which is the advantage of encapsulation?
A.Only public methods are needed.
B.No exceptions need to be thrown from any method.
C.Making the class final causes no consequential changes to other code.
D.It changes the implementation without changing the interface and causes no consequential changes to other code.
E.It changes the interface without changing the implementation and causes no consequential changes to other code.

ANS: D
4. Which of the following most directly supports retrieval of stored objects based on a unique key of String type?
A.Map
B.Set
C.List
D.Collection
E.Enumeration

ANS: A

5. Which statement is true about a non-static inner class?
A.It must implement an interface.
B.It is accessible from any other class.
C.It can only be instantiated in the enclosing class.
D.It must be final if it is declared in a method scope.
E.It can access private instance variables in the enclosing object.
ANS: E

6. Which are keywords in Java (select all that apply)?
A.NULL
B.sizeof
C.friend
D.extends
E.synchronized

ANS: D,E
7. Which declares an abstract method in an abstract Java class?
A.public abstract method();
B.public abstract void method();
C.public void abstract Method();
D.public void method() {abstract;/}
E.public abstract void method() {/}
ANS: A,B
- Thanks
 
deekasha gunwant
Ranch Hand
Posts: 396
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi doit,
i'm with u except for the last one.
for which only B is correct.
option A is wrong because it does not specifies any return type for the function.
for the rest i agree with u.
regards
deekasha
 
Anonymous
Ranch Hand
Posts: 18944
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I agreed. For the last question you need to specify what the method will return. Therefore, A is not correct.
------------------
 
vidya
Ranch Hand
Posts: 47
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi !
For the first question, won't the compiler say ' x may not have been initialised' ? But that is not one of the options..
But , I doubt, will it compile without you initialising the variable?
please tell me what I am missing...
thanks,
Vidya.
 
Ajith Kallambella
Sheriff
Posts: 5782
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Vidya,
Read the question again carefully. The variable x is a class variable and not a local variable. Hence it gets initialized to the default value( 0 for integral type ).
Class variables are automatically initialized to their default values, unless other values are specified by you. On the other hand, local variablesdon't get auto-initialized and cannot be referenced before initialization. The only exception to this rule is arrays. Arrays whether local or class-level, always gets initialized.
Hope this helps,
Ajith
 
vidya
Ranch Hand
Posts: 47
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
O , yes Ajith, I got it!!
Thanx a lot!
Vidya.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic