• 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

Sample Questions from Sun

 
Ranch Hand
Posts: 143
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Found these from one of the mocks
1) A sample question provided by Sun
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.

2) A sample question provided by Sun
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

3) A sample question provided by Sun
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.

4) A sample question provided by Sun
What can contain objects that have a unique key field of String type, if it is required to retrieve the
objects using that key field as an index?
A.Map
B.Set
C.List
D.Collection
E.Enumeration

5) A sample question provided by Sun
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.

6) A sample question provided by Sun
Which are keywords in Java?
A.NULL
B.sizeof
C.friend
D.extends
E.synchronized
Select all valid answers.

7) A sample question provided by Sun
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() {}

8) A sample question provided by Sun
Which code fragments would correctly identify the number of arguments passed via command line to a
Java application, excluding the name of the class that is being invoked?
A. int count = args.length;
B. int count = args.length - l;
C. int count=0;
while (args [count]!=null) count ++;
D. int count=0;
while(!(args[count].equals(""))) count ++;}

9) A sample question provided by Sun
FilterOutputStream is the parent class for BufferedOutputStream, DataOutputStream and
PrintStream. Which classes are a valid argument for the constructor of a FilterOutputStream?
A. InputStream
B. OutputStream
C. File
D. RandomAccessFile
E. StreamTokenizer

10) A sample question provided by Sun
Given the following method body:
1)
2) {
3) if (atest()) {
4) unsafe();
5) }
6) else {
7) safe();
8) }
9) }
The method "unsafe" might throw an AWTException (which is not a subclass of RunTimeException). Which
correctly completes the method of declaration when added at line one?
A. public AWTException methodName()
B. public void methodName()
C. public void methodName() throw AWTException
D. public void methodName() throws AWTException
E. public void methodName() throws Exception

11) A sample question provided by Sun
Given a TextArea using a proportional pitch font and constructed like this:
TextField t = new TextArea("12345", 5, 5);
Which statement is true?
A. The displayed width shows exactly five characters on each line unless otherwise constrained
B. The displayed height is five lines unless otherwise constrained.
C. The maximum number of characters in a line will be five.
D. The user will be able to edit the character string.
E. The displayed string can use multiple fonts.

11) A sample question provided by Sun
Given this skeleton of a class currently under construction:
public class Example {
int x, y;
public Example(int a) {
//lots of complex computation
x=a;
}
public Example(int a, int b) {
// do everything the same as single argument
// version of constructor
//including assignment x = a
y = b;
}
}
What is the most concise way to code the "do everything..." part of the constructor taking two
arguments?
Short answer, like "one(a)" ,do not add the semicolon at the end,

12) A sample question provided by Sun
Which correctly create a two dimensional array of integers?
A. int a[][] = new int[10,10]
B. int a[10][10] = new int[][];
C. int a[][] = new int [10][10];
D. int []a[] = new int [10][10];
E. int []a[] = new int[10][10];
Select all correct answers.

13) A sample question provided by Sun
Which are keywords in Java?
A. sizeof
B. abstract
C. native
D. NULL
E. BOOLEAN
Select all valid answers.

14) A sample question provided by Sun
Which are correct class declarations? Assume in each case that the text constitutes the entire contents of
a file called Fred.java on a system with a case-significant file system.
A. public class Fred {
public int x = 0;
public Fred (int x) {
this.x = x;
}
}
B. public class fred
public int x = 0;
public fred (int x) {
this.x = x;
}
}
C. public class Fred extends MyBaseClass, MyOtherBaseClass {
public int x = 0;
public Fred (int xval) {
x = xval;
}
}
D. protected class Fred {
private int x = 0;
private Fred (int xval) {
x = xval;
}
}

E. import java.awt.*;
public class Fred extends Object {
int x;
private Fred (int xval) {
x = xval;
}
}

15) A sample question provided by Sun
A class design requires that a particular member variable must be accessible for direct access by any
subclasses of this class, but otherwise not by classes which are not members of the same package.
What should be done to achieve this?
A. The variable should be marked public
B. The variable should be marked private
C. The variable should be marked protected
D. The variable should have no special access modifier
E. The variable should be marked private and an accessor method provided

16) A sample question provided by Sun
Which correctly create an array of five empty Strings?
A. String a [] = new String [5];
for (int i = 0; i < 5; a[i++] = "");
B. String a [] = {"", "", "", "", ""};
C. String a [5];
D. String [5] a;
E. String [] a = new String [5];
for (int i = 0; i < 5; a[i++] = null);

17) A sample question provided by Sun
Which cannot be added to a Container?
A. an Applet
B. a Component
C. a Container
D. a Menu
E. a Panel
-Arun
:roll: :roll:
 
Ranch Hand
Posts: 3244
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Arun
Not to be rude but, you've got to be kidding me!!
1. You just posted 15 questions from the Sun mock exam, if this is from the version that you paid for, then I'm fairly sure you shouldn't be passing them around for free.
2. In the future if you have a large number of questions it is probably better to post them in individual topics unless they are related. That way other people can find them later if they do a search. The other reason is that the discussion of one question can become quite large and could cover up all of the other answers making it impossible to find any info from the post.
3. You don't ask a question of your own here. Your topic is 'Sample questions from Sun' and your right they are. Are you just posting these for everyone to enjoy or do have a question on them? If you have a question you should ask it after you have tried to find out the answer yourself.
4. When you post large numbers of questions like this people may not want to take the time to asnwer them all - not knowing what part it is you need help on - or even if you need help at all. You'll get a much better response with one or two related questions you have and what part of them you dont understand.
 
Arun Pai
Ranch Hand
Posts: 143
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Dave,
I am sorry, point taken note. I just posted thinking that it will help people who were hunting for them. I am not posting this for fun, neither I paid for it to circulate free on this site. I found them at sarga's test and thought let me share this with others.In future I will try to abide by the rules over here. Sorry again
-Arun
 
Dave Vick
Ranch Hand
Posts: 3244
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Arun
Great idea andI'm sure many people will get some value out of them. In the future though you might consider a link to the place where you fond them. that way people can get the entire question and the answers too.
Also, a little introduction in your post would be good to - that way no-one tries to answer all of these thnking you need help
Foe anyone who is interested here is the Sun Practice test site.
 
Arun Pai
Ranch Hand
Posts: 143
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Dave,
Lovely link, I have found treasure.Here's the link to Sarga's Test by Levteck.com for those who are looking out for answers.

-Arun
 
No holds barred. And no bars holed. Except this tiny ad:
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic