Java: Classes - Online Test

Test Difficulty Level: Medium

Syllabus of Test

Questions based on the Basic knowledge about various classes of Java.

Sample Question from this online test:

Question: Any concept you wish to implement in a Java program must be encapsulated within a class ?

Option A: True

Option B: False

Option C: -

Option D: -

To answer, click the "Start This Test" button below.

Start this Test






Comments

kanak jiya on 2009-03-28 16:13:35 wrote,

in question no 4 ...u have stated that the variables defined in the class are known as instance variables but its not true..we can also declare static variables in the classes and they are called as class variables..

Shamit Kumar Tomar on 2009-03-28 18:10:07 wrote,

@kanak,
Thanks for pointing out the mistake. We have modified the question accordingly.

Prashant Gaur on 2009-03-28 21:45:31 wrote,

@kanak jiya,
Thanxx for the comments dear, the mistake has been rectified now..!!!

Raj Pal Sharma on 2011-01-19 22:47:46 wrote,

please check the answers of question 11th and 19th

syed abdul on 2011-03-01 12:21:53 wrote,

yeh.....

soterescon con on 2011-04-09 21:59:54 wrote,

question 19 i think is wrong

Anshul Gupta on 2011-04-28 04:02:15 wrote,

Dear answer no.11 is wrong from your side.
It is a two step process.
Read this one....

When you create a class, you are creating a new data type. You can use this type to declare objects of that type. However, obtaining objects of a class is a two-step process. First, you must declare a variable of the class type. This variable does not define an object. Instead, it is simply a variable that can refer to an object. Second, you must acquire an actual, physical copy of the object and assign it to that variable. You can do this using the new operator. The new operator dynamically allocates (that is, allocates at run time) memory for an object and returns a reference to it. This reference is, more or less, the address in memory of the object allocated by new. This reference is then stored in the variable. Thus, in java, all class objects must be dynamically allocated. Let’s look at the details of this procedure.



In the preceding sample programs, a line similar to the following is used to declar an object of type Box.



Box mybox = new Box ();



This statement combines the two steps just described. It can be rewritten like this to show each step more clearly;



Box mybox;

mybox = new Box();



This first line declares mybox as a reference to an object of type Box. After this line executes, mybox contains the value the value null, which indicates that it does not yet point to an actual object. Any attempt to use mybox at this point will result in a compile-time error. The next line allocates an actual object and assigns a reference to it to mybox. After the second line executes, you can use mybox as if it were Box object. But in reality, mybox simply holds the memory address of the actual Box object. The effect of these two lines of code is depicted .

usha raj on 2011-05-17 12:43:31 wrote,

it is very useful for me

jalad sharma on 2011-07-05 14:41:25 wrote,

not so tough

jainendra pathak on 2011-12-28 05:56:27 wrote,

Question 3's answer should be D )None of these because its java is case sensitive. and option B)Class is not correct it will give compilation error .It should be "class" then only option B will correct.

Queenie Macel on 2012-02-01 21:34:53 wrote,

was very helpfull thanks