aspose file tools*
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes please answer my query? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "please answer my query?" Watch "please answer my query?" New topic
Author

please answer my query?

payal sharma
Ranch Hand

Joined: Oct 04, 2000
Posts: 57
I am unable to understand this?

here why I am getting compile time error as AllFinals.java:7: Identifier expected.
v=new Vector();
Although I am changing the refrence of the final object not the object itself.
I can change its reference in contructor if I put v=new Vector() in constructor.
but here

AllFinals.java:5: Blank final variable 'v' may not have been initialized. It must be assigned a value in an initializer, or in every constructor.
final Vector v;
but If assigned value in initializer then

I am geting error
AllFinals.java:15: Undefined variable or class name: v
System.out.println(v.isEmpty());
^
Now
static {
final Vector v;
v=new Vector();
}
making initializer static giving the same problem why?
^
Q2 Why top level class can not be static?
Q3

here object a1 is of tyep AnInterface but reference of AnInterfaceImpl.
Call method on this object is giving compile time error methodOne do not catch or throw Exception.
But why

this compiles and with out and error or exception.
Q4
why

this giving not equal
Bill Tripper
Greenhorn

Joined: May 30, 2001
Posts: 24
Q1: The statement "v = new Vector()" is floating out there where your variable declarations belong. You can put it into an initializer block, e.g., "{v = new Vector();}" and it will work.
Instead of:
{
final Vector v;
v=new Vector();
}
use:
final Vector v;
{
v = new Vector();
}
Thomas Paul
mister krabs
Ranch Hand

Joined: May 05, 2000
Posts: 13974
or why not just code:
final Vector v = new Vector();
------------------
Tom - SCJP --- Co-Moderator of the Programmer Certification Forums


Associate Instructor - Hofstra University
Amazon Top 750 reviewer - Blog - Unresolved References - Book Review Blog
Mini Pilla
Ranch Hand

Joined: Jul 15, 2001
Posts: 112

Ya this will also work or rather should.

Originally posted by Thomas Paul:
or why not just code:
final Vector v = new Vector();

wei luo
Greenhorn

Joined: Mar 15, 2001
Posts: 23
I think "final Vector v;
public AllFinals()
{ v = new Vector();
}
will also work.
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: please answer my query?