Exforsys

Free Training

Quick java quiz - 100 points donated to the person who first answers it correctly

This is a discussion on Quick java quiz - 100 points donated to the person who first answers it correctly within the Java Tutorials forums, part of the Articles and Tutorials category; Heres a nice quiz for Java Enthusiasts... Answer this yourself, just to self-test. If you post replies, I'll verify the ...

Go Back   Exforsys > Articles and Tutorials > Java Tutorials

Exforsys.com


Java Tutorials Java Tutorials and Articles Discussions

Reply

 

LinkBack Thread Tools Search this Thread
  #1 (permalink)  
Old 04-29-2006, 08:43 AM
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
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Sponsored Links
  #2 (permalink)  
Old 04-30-2006, 02:58 PM
Member
 
Join Date: Apr 2006
Posts: 85
cbdarts is an unknown quantity at this point
Quote:
Originally Posted by ashlee
hi,

Answers are as under

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

A- In the real world, you often have many objects of the same kind. For example, your bicycle is just one of many bicycles in the world. Using object-oriented terminology, we say that your bicycle object is an instance of the class of objects known as bicycles. Bicycles have some state (current gear, current cadence, two wheels) and behavior (change gears, brake) in common. However, each bicycle's state is independent of and can be different from that of other bicycles

Objects are key to understanding object-oriented technology. You can look around you now and see many examples of real-world objects: your dog, your desk, your television set, your bicycle.
Real-world objects share two characteristics: They all have state and behavior. For example, dogs have state (name, color, breed, hungry) and behavior (barking, fetching, wagging tail). Bicycles have state (current gear, current pedal cadence, two wheels, number of gears) and behavior (braking, accelerating, slowing down, changing gears).

relationship-The has-a relationship means that one type of object contains another or is composed of another. Some examples are: a car has-an engine, a bicycle has-a wheel, and a coffee cup has coffee

The is-a relationship means that one type of object is a more specific version of a general type. Some examples are: a car is-a vehicle, a bicycle is-a vehicle, and a coffee cup is-a cup.

The uses-a relationship means that during some activity, one type of object uses another type of object. Some examples are: a car uses-a squeegee (during a window-washing activity), a bicycle uses-a pump (during a tire-pumping activity), and a coffee cup uses-a stirrer (during a stirring activity).

2."null" is not a keyword, but a special literal of the null type. It can be cast to any reference type, but not to any primitive type such as int or boolean. The null literal doesn't necessarily have value zero. And it is impossible to cast to the null type or declare a variable of this type

3.A constructor is executed when an object is instantiated from a class .It is possible to take initial parameters (like the initial mileage in our example) and to initialize the variables of the newly created object. Constructors are declared like other methods but use the name of the class . The parameter follow the name of a method and are enclosed in parentheses (even if there are no parameters).

Use-Constructors have one purpose in life: to create an instance of a class. This can also be called creating an object, as in:



Platypus p1 = new Platypus();


The purpose of methods, by contrast, is much more general. A method's basic function is to execute Java code.

rest answers i will give you in short span time...

Thanks
ashlee

Good answers, Ashlee. I'm looking forward to the rest of the answers, so I can donate 100 points to your cause...
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #3 (permalink)  
Old 05-14-2006, 12:56 AM
Member
 
Join Date: Apr 2006
Posts: 85
cbdarts is an unknown quantity at this point
Hi Allan. The Points you earn are shown alongside your post on the left hand side. I am referring to the points on this site only.

You earn points when you make a post, and you can use these points to do stuff like buy animated avatars, highlight your username and stuff.

Its basically fun-stuff, so I can see why nobody has bothered completeing the quiz....

Chaitanya
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Reply

Bookmarks

Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is On
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads

Thread Thread Starter Forum Replies Last Post
Getting Started With Java Programming !! insane Java Tutorials 7 04-26-2006 03:19 PM


All times are GMT -4. The time now is 03:11 PM.


Powered by vBulletin® Version 3.8.4
Copyright ©2000 - 2010, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.3.0
Copyright 2004 - 2009 Exforsys Inc. All rights reserved.