File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes Constructor, Scope, Final variables, Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Soft Skills this week in the Jobs Discussion forum!
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "Constructor, Scope, Final variables, " Watch "Constructor, Scope, Final variables, " New topic
Author

Constructor, Scope, Final variables,

amit sanghai
Ranch Hand

Joined: Dec 05, 2000
Posts: 231

Hi everybody,
I ahve 3 questions:
Q1) Is it necessary for all Java classes to have atleast one constructor ?
Q2) Variables declared inside a method as final retain their value between invocations of the method in which they are defined. True or False
Q3) In the following code after which line does the variable var go out of scope ?

void func() {
for (int i=0; i<10; i++)
{
double var= i*3.2;
for(int j=0; j<10; j++) {
String s= String.valueOf(var*j);
System.out.println(s);
}
}
}

a) Line number 7
b) Line number 8
c) Line number 9

Bharatesh H Kakamari
Ranch Hand

Joined: Nov 09, 2000
Posts: 198
Q1) Is it necessary for all Java classes to have atleast one constructor ?

If you mean that the programmer's HAS to place the constructor in every java class. Then the answer is no. But java always puts a constructor to a class implicitly if one is not provided by a class designer. This implicit constructor is called the default constructor which does not have any arguments and the modifier is that of the class. If the class is public then the modifier is also public and so on.

Q2) Variables declared inside a method as final retain their value between invocations of the method in which they are defined. True or False
false. This is just to confuse C / VB programmers who know that a static variable's value is retained between method invocations.
Q3) In the following code after which line does the variable var go out of scope ?

a) Line number 7
b) Line number 8
c) Line number 9

I think it is after line 8 or at line 9
Simon Cockayne
Ranch Hand

Joined: Dec 09, 2000
Posts: 214
The variable var is out of scope AFTER the closing brace on line 9.

SCJP 1.4 (93%)<br />SCJD (In progress. It can run, but it can't hide...)
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Constructor, Scope, Final variables,