View Single Post

  #1 (permalink)  
Old 04-29-2006, 09:43 AM
cbdarts cbdarts is offline
Member
 
Join Date: Apr 2006
Posts: 85
cbdarts is an unknown quantity at this point
Question Quick java quiz - 100 points donated to the person who first answers it correctly

Heres a nice quiz for Java Enthusiasts...

Quote:
Answer this yourself, just to self-test. If you post replies, I'll verify the answers, else you could lookup possible answers in your favourite java spots.

--------------------------------------------------

1) Object-oriented programming uses objects and classes. Define what are classes and what are objects? What is the relationship between classes and objects?

2) Explain precisely what "null" means in Java, why this special value is used, and what it is used for.

3) What is a constructor? What is the use of a constructor in a class?

4) Suppose that KAPE is the name of a class and that fruit is a variable of type KAPE. What is the meaning of the statement "fruit = new KAPE();"? That is, what does the computer do when it executes this statement? (Try to give a complete answer - this is quite a long one, so be concise.)

5) What is meant by these terms "instance variable" and "instance method"? How are they different from "static variables" and "static methods"?

6) Explain what is meant by the terms subclass and superclass. What is the use of a superclass & subclass?

7) Explain the term polymorphism in brief

8) Java uses "garbage collection" in terms of memory management. Explain what is meant here by garbage collection in general. What is the alternative to garbage collection?

9) For this problem, write a very simple and complete class. The class represents a counter that counts 0, 1, 2, 3, 4,.... The name of the class should be Counter. It has one protected instance variable representing the value of the counter. It has two instance methods: increment() adds one to the counter value, and getValue() returns the current counter value. Write a complete definition for the class, Counter. And make sure it works right.

10) This problem uses the Counter class from the prev question. The following program segment is meant to simulate tossing of a coin 10 times. It should use two Counter objects, headCount and tailCount, to count the number of heads and the number of tails. Fill in the blanks so that it will do so.

Code:
          Counter headCount, tailCount;
          tailCount = new Counter();
          headCount = new Counter();
          for ( int flip = 0;  flip < 10;  flip++ ) {
             if (Math.random() < 0.5)    // There's a 50/50 chance that this is true.
             
                 ______________________ ;   // Count "head".
                 
             else
             
                 ______________________ ;   // Count "tail".
          }
          
          System.out.println("There were " + __ + " heads.");
          
          System.out.println("There were " + __ + " tails.");

Have fun, guys! The first one to post a correct reply gets 100 points donated from me. Offer valid 24 hours and stuff...

Chaitanya
Reply With Quote