Win a copy of Programmer's Guide to Java SE 8 Oracle Certified Associate (OCA) this week in the OCAJP forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Please help me !!!!!answers for sun sample questions

 
bala_chocos
Ranch Hand
Posts: 48
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hi
anyone can help me . below is sun sample questions.please give the correct answer
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);}
}
The output "Value is 0" is printed.
An object of type NullPointerException is thrown.
An "illegal array declaration syntax" compiler error occurs.
A "possible reference before assignment" compiler error occurs.
An object of type ArrayIndexOutOfBoundsException is thrown.

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 FlowLayout
a GridLayout
the center area of a BorderLayout
the East or West area of a BorderLayout
the North or South area of a BorderLayout

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

4. Which of the following most directly supports retrieval of stored objects based on a unique key of String type?
Map
Set
List
Collection
Enumeration

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

6. Which are keywords in Java (select all that apply)?
NULL
sizeof
friend
extends
synchronized

7. Which declares an abstract method in an abstract Java class?
public abstract method();
public abstract void method();
public void abstract Method();
public void method() {abstract;/}
public abstract void method() {/}

1 a
2 a
3 e
4 c
5 c,e
6 d,e
7 b,c
The above mentioned answers are correct or not.if it is wrong
give me the correct answer ans explanation

------------------
 
Anonymous
Ranch Hand
Posts: 18944
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

hi
this is what i think ..
1 a
2 a
3 c (encapsulation means hide the implementation details so these details can be changed easily without changing the interface).
4 c
5 e (non-static inner class can be instatiated outside the enclosing class - outer.inner ob = new outer().inner() )
6 d e
7 b (return type has to be immediately before the method name)

Plz. let me know if i have gone wrong somewhere
Thanx
Padmanabh
 
Anonymous
Ranch Hand
Posts: 18944
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
can you plz. explain why b is not correct.
class Class1 {
class Class2 {
}
}
public class Test {
public static void main(String args[]) {
Class1.Class2 c = new Class1().new Class2();
}
}
Thanks
 
mehrar
Greenhorn
Posts: 19
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
3 Answer should be d. As in Encapsulation the idea is to change the implemenation keeping the interface same so that the other code doesnt require the code changes.
 
chetan nain
Ranch Hand
Posts: 159
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
try making your inner class Class2 private and see the result.
since an inner class may be private, it is not accessible from the same package classes
 
Aull Sahar
Greenhorn
Posts: 14
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
7. declaration of abstract method should be:
public abstract void method();
There is only one right answer in 7 b.
NOT public void abstract method();
 
MahaAdd
Greenhorn
Posts: 28
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,
the answers are now available on the same site:sun.java.com
u can look into that,
maha
Originally posted by bala_chocos:
hi
anyone can help me . below is sun sample questions.please give the correct answer
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);}
}
The output "Value is 0" is printed.
An object of type NullPointerException is thrown.
An "illegal array declaration syntax" compiler error occurs.
A "possible reference before assignment" compiler error occurs.
An object of type ArrayIndexOutOfBoundsException is thrown.

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 FlowLayout
a GridLayout
the center area of a BorderLayout
the East or West area of a BorderLayout
the North or South area of a BorderLayout

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

4. Which of the following most directly supports retrieval of stored objects based on a unique key of String type?
Map
Set
List
Collection
Enumeration

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

6. Which are keywords in Java (select all that apply)?
NULL
sizeof
friend
extends
synchronized

7. Which declares an abstract method in an abstract Java class?
public abstract method();
public abstract void method();
public void abstract Method();
public void method() {abstract;/}
public abstract void method() {/}

1 a
2 a
3 e
4 c
5 c,e
6 d,e
7 b,c
The above mentioned answers are correct or not.if it is wrong
give me the correct answer ans explanation


 
jesse
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
question 4)
the answer is a, a map uses a unique key which enables searching
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic