• 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
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

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

 
Ranch Hand
Posts: 48
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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

------------------
 
Ranch Hand
Posts: 18944
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Greenhorn
Posts: 19
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Ranch Hand
Posts: 159
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Greenhorn
Posts: 14
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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();
 
Greenhorn
Posts: 28
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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


 
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
question 4)
the answer is a, a map uses a unique key which enables searching
 
reply
    Bookmark Topic Watch Topic
  • New Topic