This week's book giveaway is in the Design forum.
We're giving away four copies of Design for the Mind and have Victor S. Yocco on-line!
See this thread for details.
Win a copy of Design for the Mind this week in the Design forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

set of questions

 
Parameswaran Thangavel
Ranch Hand
Posts: 485
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hi explain with the output


public class Q1eec {
static void test(int i) {
int j = i/2;
int k = i >>> 1;
assert j == k : i;
}

public static void main(String[] args) {
test(0);
test(2);
test(-2);
test(1001);
test(-1001);
}
}






Given the following code, which statements concerning the objects referenced through the member variables i, j and k are true, given that any thread may call the methods a(), b() and c() at any time?

class Counter {
int v = 0;
synchronized void inc() { v++; }
synchronized void dec() { v--; }
}
public class Q7ed5 {
Counter i;
Counter j;
Counter k;
public synchronized void a() {
i.inc();
System.out.println("a");
i.dec();
}
public synchronized void b() {
i.inc(); j.inc(); k.inc();
System.out.println("b");
i.dec(); j.dec(); k.dec();
}
public void c() {
k.inc();
System.out.println("c");
k.dec();
}
}





Which statements are true regarding the execution of the following code?

public class Q3a0a {
public static void main(String[] args) {
int j = 5;

for (int i = 0; i<j; i++) {
assert i < j-- : i > 0;
System.out.println(i*j);
}
}
}






What will be written to the standard output when the following program is run?

class Base {
int i;
Base() { add(1); }
void add(int v) { i += v; }
void print() { System.out.println(i); }
}
class Extension extends Base {
Extension() { add(2); }
void add(int v) { i += v*2; }
}
public class Qd073 {
public static void main(String[] args) {
bogo(new Extension());
}
static void bogo(Base b) {
b.add(8);
b.print();
}
}
 
Parameswaran Thangavel
Ranch Hand
Posts: 485
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
any one please
 
Joe Sondow
Ranch Hand
Posts: 195
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Parameswaran, I usually try to answer your questions, but I think I can do you a better service by suggesting that you ask them in a way that makes it easier for others to help you. A few suggestions:

1. Use the UBB "code" tags around your code to preserve the indentation.

2. Make sure your code uses proper indentation so it's easier to read.

3. Only ask one question per discussion thread. If you have 4 questions, post 4 separate topics. This helps readers focus on one issue and discuss that one issue.

4. Proofread your post to make sure it makes sense. This topic, for example, has several mock exam questions that ask "Which statements are true about this?" but you forgot to list any of the possible statements.

5. Read and understand everything in the How to Ask Questions the Smart Way faq.
[ March 12, 2006: Message edited by: Joseph Sondow ]
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic