aspose file tools*
The moose likes Beginning Java and the fly likes Pl explain these Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Pl explain these" Watch "Pl explain these" New topic
Author

Pl explain these

vatsalya rao
Ranch Hand

Joined: Feb 14, 2007
Posts: 63
6) What would be the output of the following code?


private class Trouble{
int count;

public void increment(){
count++;
System.out.println(count);
}

public void decrement(){
count--;
System.out.println(count);
}

public static void main(String args[]){
Trouble tsome=new Trouble();
tsome.increment();
tsome.decrement();
}
}

Whats wrong with this code?The answer given is COMPILE ERROR.Where is the error lying in this code?


2) Which of the following are not a part of a method signature?

(A) Name of Method

(B) Type of Method parameter(s)

(C) Order of method parameter(s)

(D) Return type of method-

The answer given is D.We will specify return type

also in method signature right?Example is int add(int,int);

But why the answer is given like that?



3)8) In the following what access modifier could be placed in the
place of FFFF to let the code compile without error?

class Super
{
protected void test(){
};
}

class Sub extends Super
{
FFFF void test()
{
super.test();
}
}

Choose from the options below:
(i) Replace FFFF by private
(ii) Replace FFFF by public
(iii) Remove FFFF
(iv) Replace FFFF by protected

(A) i,iii are correct

(B) ii,iv are correct

(C) only iii is correct

(D) only ii is correct

Here the answer is B.

Can anybody please explain the uderlying concept for this answer?
Michael Jennings
Greenhorn

Joined: Jul 04, 2007
Posts: 20
Hi,

First one. Your class
Trouble
must not be private. You cannot have a top-level class as private. A top-level class can be public, abstract or final.

Second one. Return-type is not part of method signature.

Third one. The method test() in class Super can be overloaded in class Sub. When doing so, the accessibility of the overloading method(test() of Sub) cannot be more restricted than the overloaded method(test() of Super).
Campbell Ritchie
Sheriff

Joined: Oct 13, 2005
Posts: 36486
    
  16
Michael Jennings, thank you, but it doesn't help anybody to learn if you simply answer this sort of exam question. You ought to have asked what Vats Rao thought the correct answers were.
Manuel Leiria
Ranch Hand

Joined: Jul 13, 2007
Posts: 171
Originally posted by vats rao:
6) What would be the output of the following code?


private class Trouble{
int count;

public void increment(){
count++;
System.out.println(count);
}

public void decrement(){
count--;
System.out.println(count);
}

public static void main(String args[]){
Trouble tsome=new Trouble();
tsome.increment();
tsome.decrement();
}
}

Whats wrong with this code?The answer given is COMPILE ERROR.Where is the error lying in this code?


2) Which of the following are not a part of a method signature?

(A) Name of Method

(B) Type of Method parameter(s)

(C) Order of method parameter(s)

(D) Return type of method-

The answer given is D.We will specify return type

also in method signature right?Example is int add(int,int);

But why the answer is given like that?



3)8) In the following what access modifier could be placed in the
place of FFFF to let the code compile without error?

class Super
{
protected void test(){
};
}

class Sub extends Super
{
FFFF void test()
{
super.test();
}
}

Choose from the options below:
(i) Replace FFFF by private
(ii) Replace FFFF by public
(iii) Remove FFFF
(iv) Replace FFFF by protected

(A) i,iii are correct

(B) ii,iv are correct

(C) only iii is correct

(D) only ii is correct

Here the answer is B.

Can anybody please explain the uderlying concept for this answer?


Compile, run and see what you've got and then, if you have doubts about the results, will be glad to help.


Manuel Leiria<br /> <br />--------------<br />Peace cannot be kept by force; it can only be achieved by understanding. <br /> Albert Einstein
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Pl explain these
 
Similar Threads
Question MindQ Mock exam
q on overloading and overriding
question from Sun Guoqiao's homepage
K&B book self test 15 on page 409
SCJP Study Exam Chapter 5 Question 15