Win a copy of Head First Android this week in the Android forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Tim Cooke
  • Campbell Ritchie
  • Paul Clapham
  • Ron McLeod
  • Liutauras Vilda
Sheriffs:
  • Jeanne Boyarsky
  • Rob Spoor
  • Bear Bibeault
Saloon Keepers:
  • Jesse Silverman
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
Bartenders:
  • Piet Souris
  • Al Hobbs
  • salvin francis

please answer my query?

 
Ranch Hand
Posts: 57
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
Greenhorn
Posts: 24
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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();
}
 
mister krabs
Posts: 13974
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
or why not just code:
final Vector v = new Vector();
------------------
Tom - SCJP --- Co-Moderator of the Programmer Certification Forums
 
Ranch Hand
Posts: 112
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Ya this will also work or rather should.

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


 
Greenhorn
Posts: 23
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I think "final Vector v;
public AllFinals()
{ v = new Vector();
}
will also work.
 
You showed up just in time for the waffles! And this tiny ad:
Building a Better World in your Backyard by Paul Wheaton and Shawn Klassen-Koop
https://coderanch.com/wiki/718759/books/Building-World-Backyard-Paul-Wheaton
reply
    Bookmark Topic Watch Topic
  • New Topic