• 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 all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Jeanne Boyarsky
  • Liutauras Vilda
  • Campbell Ritchie
  • Tim Cooke
  • Bear Bibeault
Sheriffs:
  • Paul Clapham
  • Junilu Lacar
  • Knute Snortum
Saloon Keepers:
  • Ron McLeod
  • Ganesh Patekar
  • Tim Moores
  • Pete Letkeman
  • Stephan van Hulst
Bartenders:
  • Carey Brown
  • Tim Holloway
  • Joe Ess

Let's have a look!  RSS feed

 
Ranch Hand
Posts: 145
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
======================================================================
1.
sublist(1,1) returns nothing?
Ans: Yes
======================================================================
2.
abstract class hoho {
}
public class Test() {
hoho A;

}
ok?
Ans: compile error.
======================================================================
3.
when override finalize();
have to put super() in?;
Ans: No.
======================================================================
4. in constructors:
can have this() and super() at the same time?
Ans: Cannot, as they both have to be first non-comment line if defines.
======================================================================
5. package ernie;
public class A() {
}
in other file:
public class B extends A() {
}
Will this compile?
Ans: Yes, since A is defined public, so accessible for all other classes.
======================================================================
6. if (true | false) works? //line 1
if (0 | 100) works? //line 2
Ans: Line 1 will, Line 2 won't

======================================================================
7.
class Mammal{
Mammal(){
System.out.println("Creating Mammal");
}
}
public class Human extends Mammal{
public static void main(String argv[]){
Human h = new Human();
}
Human(){
//HERE
System.out.println("Creating Human");
}
}
When this code runs the string "Creating Mammal" is output first due to the implicit call to the no-args constructor at the base of the hierarchy.
what is u put a super() in //HERE?
Ans: Same output, constructor mammal will not be call implicity.
======================================================================
8. can inner class create instance of outer class?
Ans: Yes.
======================================================================
9. anoymous inner class must either extends a class or implement an interface?
Ans: Yes.
======================================================================
10. Thread.sleep() method is static
so.. Thread a = new Thread()
Thread b = new Thread()
a.sleep(100); (this line equals Thread.sleep(100))...
how do the JVM knows which thread to stop???
since sleep is a class method (static) will it stop b as well?
if not, why?
Ans: No. JVM will stop the running thread.
======================================================================
11. notifyall
will notify all waiting thread... but actually..only one thread will re-get the lock again..
and u don't know which.. how it is differ from notify?
Ans: Not True, actually all threads in waiting will be waken up one by one.
======================================================================
12. List interface = sorted?
Ans: No. (not sure about this...)
======================================================================

13. Boolean and Integer are immutable object...
so...what happens when change values?
Ans: New object will be created as String.
======================================================================

14.
public class Test {
Test() {
new Test();
}
public static void main(String[] args) {
new Test();
}
}
What will happens?
Ans: infinite loop
======================================================================

15. GridLayout(1,2)
but add 5 components, what happens?
Ans: Same effect as GridLayout(1,5) was used.
======================================================================
17. int a() {
//no return statement
}
Ans: Fail to compile.
======================================================================

18. public static void main throws IOException {
//but no statements here throws IOException
int i = 0;
}

what will happens?
Ans: Fail to compile.
======================================================================

19. can we define static varaiable in static method?
Ans: No, Fail to compile. Variables in method should be out of scope
when method exit.. so no point for static.
======================================================================
19. can we define static inner class in static method?
Ans: No, Fail to compile.
======================================================================
Any Comments??
Wish me luck in my exam!
 
Ranch Hand
Posts: 371
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I think for 11. notifyAll, the first answer was not wrong. All Threads in waiting pool will be notified(into ready state), but only one will gain the lock to the object(into running state). Whereas notify will only notify one Thread into ready state.
Good luck.
 
Ranch Hand
Posts: 2373
Java MySQL Database Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Well Ernest, very good picks frm the bunch of grasses!
In ur Q5 u have to import ernie.B or ernie.* or have to use ernie.A--otherwise compile time error. Q11 i agree with Cameron's answer as well as ur explanation. But Q18 will not fail to compile....try the following code. It will both compile and run fine! Anyway, best wishes for ur exam. I m appearing 27th, when r u???

------------------
Muhammad Ashikuzzaman (Fahim)
When you learn something, learn it by heart!
 
Greenhorn
Posts: 26
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Ernest, I believe for question#2, the code is okay, no compilation error is generated. Please correct me if I am wrong.
 
Ranch Hand
Posts: 356
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Can somebody explain me Q13 ?
AAA
--Farooq
======================================================================

13. Boolean and Integer are immutable object...
so...what happens when change values?
Ans: New object will be created as String.
======================================================================
 
Christy Smith
Greenhorn
Posts: 26
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
All the wrapper class are immutable, like String, the object once created cannot be changed. If the object's value is changed, a new object is created instead.
 
Muhammad Farooq
Ranch Hand
Posts: 356
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks Christy, I was confused with the answer that says "New object will be created as String", it just have to say "New object will be created".
--Farooq
 
Ranch Hand
Posts: 52
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The main method in Q18 is not be defined correctly.Can you see the missed code in the method definition line?
It is just "(String args[])" after "main".So the code of Q18 will not be compiled.
Am I wrong?

Originally posted by Ashik uzzaman:
[B]Well Ernest, very good picks frm the bunch of grasses!
In ur Q5 u have to import ernie.B or ernie.* or have to use ernie.A--otherwise compile time error. Q11 i agree with Cameron's answer as well as ur explanation. But Q18 will not fail to compile....try the following code. It will both compile and run fine! Anyway, best wishes for ur exam. I m appearing 27th, when r u???

[/B]



------------------
Java lover from hell!
 
Metal Zhang
Ranch Hand
Posts: 52
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I compiled them but failed.The error is:

Test1.java:6: '{' expected.
public class Test1() {
^
1 error

Originally posted by Christy Smith:
Ernest, I believe for question#2, the code is okay, no compilation error is generated. Please correct me if I am wrong.


------------------
Java lover from hell!
[This message has been edited by Metal Zhang (edited August 23, 2001).]
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!