• 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

mock exam questions -

 
Ranch Hand
Posts: 234
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
What is the result of compiling and executing the following Java class:

public class ThreadTest extends Thread {
public void run() {
System.out.println("In run");
suspend();
resume();
System.out.println("Leaving run");
}

public static void main(String args []) {
(new ThreadTest()).start();
}
}

a)Compilation will fail in the method main.
b)Compilation will fail in the method run.
c)A warning will be generated for method run.
d)The string "In run" will be printed to standard out.
e)Both strings will be printed to standard out.
f)Nothing will happen.
answer is d.
but i think the output should be e) "in run" and "leaving run"
public class Calc {
public static void main (String args []) {
int total = 0;
for (int i = 0, j = 10; total > 30; ++i, --j) {
System.out.println(" i = " + i + " : j = " + j);
total += (i + j);
}
System.out.println("Total " + total);
}
}
A. Produce a runtime error
B. Produce a compile time error
C. Print out "Total 0"
D. Generate the following as output:
i = 0 : j = 10
i = 1 : j = 9
i = 2 : j = 8
Total 30
answer is c . but according to me the answer should be d

 
Ranch Hand
Posts: 147
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
hi
answer to the second question
C. Print out "Total 0"
its easy ... beacuse the for condition is false
Samith.P.Nambiar
-------------------------------------
the harder u try the luckier u get
 
I think he's gonna try to grab my monkey. Do we have a monkey outfit for this tiny ad?
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic