• 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:
  • Campbell Ritchie
  • Tim Cooke
  • paul wheaton
  • Liutauras Vilda
  • Ron McLeod
Sheriffs:
  • Jeanne Boyarsky
  • Devaka Cooray
  • Paul Clapham
Saloon Keepers:
  • Scott Selikoff
  • Tim Holloway
  • Piet Souris
  • Mikalai Zaikin
  • Frits Walraven
Bartenders:
  • Stephan van Hulst
  • Carey Brown

abstract class

 
Ranch Hand
Posts: 115
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
some one please tell me which mistake i done in my below code

3 public abstract class Feature
4 {
5 private String age;
6
7 protected Feature( String page )
8 {
9 if ( page == null )
10 {
11 throw new NullPointerException( "age must not be null" );
12 }
13
14 age= page;
15 }
16
17 public String getAge()
18 {
19 return age;
20 }
21
22 public void setAge( final String age )
23 {
24 age = age;
25 }
26
27 public boolean equals( Object o )
28 {
29 return o != null && o.getClass().equals( getClass() ) && age.equals( ( (Feature) o ).age);
30 }
31
32 public String toString()
33 {
34 return "Feature(" + age + ")";
35 }
36 }
 
Sheriff
Posts: 7126
185
Eclipse IDE Postgres Database VI Editor Chrome Java Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Could you be more specific about what the problem is? A compiler error? Then post the error.

And please use the code tags for posting code.
 
Marshal
Posts: 80123
416
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Knute Snortum wrote: . . .
And please use the code tags for posting code.

Without line numbers, please. The code tags add the line numbers automatically.
 
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
every thing seems right.. but except for a small thing at line 24. you should use this.age = age.

 
Campbell Ritchie
Marshal
Posts: 80123
416
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Welcome to the Ranch Ravi Shankar Jha
 
sujesh Katri
Ranch Hand
Posts: 115
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
yeah i corrected it later...why final variables can't assigned like age=age;
 
Ravi Shankar Jha
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
once the age is declared final you cannot reassigned it.
compiler views age = age, as you are reassigning the value of age to itself, so you will get compile time error.
To overcome this scenario you need to specify for which age you are setting the value.
 
sujesh Katri
Ranch Hand
Posts: 115
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
for final variables is first time assignment possible or not..my lecturer said first time assignment possible for final variables,so i assigned like that.
 
Ravi Shankar Jha
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
when we will call setAge method passing a String parameter at that time first assignment will happen.
 
sujesh Katri
Ranch Hand
Posts: 115
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
for first time assignmet which value it takes...is it null value.
 
Campbell Ritchie
Marshal
Posts: 80123
416
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

sujesh Katri wrote:for final variables is first time assignment possible or not..my lecturer said first time assignment possible for final variables,so i assigned like that.

Have you tried it? Which variable is final?
What do you mean by first time assignment? You should know whether local variables, fields or parameters have default values, and what they are. If you have forgotten, please go to the Java Tutorials or Java Language specification and refresh your memory. I could not find the right sections, but try looking for the sections about definite assignment.

You have been told several times about age = age; Have you really not found out what the error in that method is?
 
He loves you so much! And I'm baking the cake! I'm going to put this tiny ad in the cake:
Smokeless wood heat with a rocket mass heater
https://woodheat.net
reply
    Bookmark Topic Watch Topic
  • New Topic