I assume anyone who knows a thing or two about java could help me by ripping through them or even having an educated guess at them. . any help would be orsm
SECTION A — MULTIPLE CHOICE QUESTIONS
Attempt ALL questions from Section A. Each question is worth 1 mark.
Question 1
Consider a program with the following declarations and statements in the main()
method.
Scanner key;
int[] values;
Turtle t1;
sc = new Scanner(System.in);
String s="x";
Which of the following is true?
A There are 0 variables of a primitive type declared and 4 reference
variables declared.
B There is 1 variable of a primitive type declared and 3 reference
variables declared.
C There are 2 variables of primitive types declared and 2 reference
variables declared.
D There are 3 variables of primitive types declared and 1 reference
variable declared.
E There are 4 variables of primitive types declared and 0 reference
variables declared.
Question 2
Consider a Java program with the following code. The actual values assigned are
omitted — they are indicated by ???, ###, and @@@
int max = ###;
int current = 1;
for(int mult = ???; mult <= max; mult = mult + 1)
{
current+=@@@;
System.out.println(current);
}
What expressions will need to be assigned so that the output when the code is
executed will be:
2
4
8
16
32
A ??? = 0 ### = 3 @@@ = mult
B ??? = 0 ### = 4 @@@ = current
C ??? = 1 ### = 4 @@@ = current
D ??? = 1 ### = 5 @@@ = mult
E ??? = 2 ### = 6 @@@ = current
Question 3
Suppose that you have a program with the following declarations and initialisation:
int outer = 0;
int inner = 0;
What values will these variables have after the following code is executed? (You
may assume that it is included in an otherwise correct Java program.)
for (int oC = 0; oC <= 2; oC = oC + 1)
{
for (int iC = oC; iC >= 0; iC = iC - 1)
{
inner = inner + 1;
}
outer = inner - 1;
}
A inner 2
outer 1
B inner 3
outer 2
C inner 4
outer 3
D inner 5
outer 4
E inner 6
outer 5
Question 4
Consider a program with the following declarations and statements in the main()
method:
char[] chars;
char char1 = '1';
int char2 = 2;
chars = new char[char2];
chars[1] = char1;
Which of the following is true?
A chars refers to an array with 1 character element.
B char2 is illegally defined.
C chars.length() is equal to 2.
D The first element of the array chars contains the value '1'.
E The last element of the array chars contains the value '1'.
Question 5
Consider a Java application with the following declarations and code in the main()
method. What will appear on the screen when the code is executed? (You may
assume that it is included in an otherwise correct Java program.)
String s, t, u;
s = new String("low");
t = new String("bow");
u = new String("sew");
if (s.indexOf('o') == -1)
{
t = new String("woe");
}
else
{
t = new String("doe");
if (s == "low")
{
u = new String("mow");
}
else
{
u = new String("row");
}
}
System.out.println(t);
System.out.println(u);
A bow
sew
B woe
sew
C doe
mow
D doe
row
E None of the above.
Question 6
Suppose that a class had been defined that has the following instance data declared:
final String WORD = new String("Hidden");
char w='w';
String word;
and a method with the header:
public String delete(String s, char x)
Which of the following would be a valid call to this method (when included in the
code of another method within the class)?
A WORD = delete(WORD,'w');
B word = delete(word, "w");
C WORD = delete(WORD, w);
D word = delete(word, w);
E WORD = delete(word, 'w');
This post has been edited by BrianNeedsJavaHelp: 08 June 2009 - 06:57 PM

New Topic/Question
This topic is locked




MultiQuote




|