• 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 all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Ron McLeod
  • Paul Clapham
  • Bear Bibeault
  • Junilu Lacar
Sheriffs:
  • Jeanne Boyarsky
  • Tim Cooke
  • Henry Wong
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • salvin francis
  • Frits Walraven
Bartenders:
  • Scott Selikoff
  • Piet Souris
  • Carey Brown

ibm test question

 
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
what will be the output for following question.

public class Cat {
int iq;
public Cat ( ) {
}
Cat(int i) { iq = i;}
}
public class TestIt extends Cat {
final Cat c = new Cat (6);
public static void main(String[] args ) {
c = new Cat(4);
c.iq = 5;
System.out.println("Cat IQ = " + c.iq);
return;
}
}

Thanks
Ketu
 
Ranch Hand
Posts: 18944
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator

Originally posted by K2 Joshi:
what will be the output for following question.

public class Cat {
int iq;
public Cat ( ) {
}
Cat(int i) { iq = i;}
}
public class TestIt extends Cat {
final Cat c = new Cat (6);
public static void main(String[] args ) {
c = new Cat(4);
c.iq = 5;
System.out.println("Cat IQ = " + c.iq);
return;
}
}

Thanks
Ketu


U will get compile-error stating Cat should be placed
in a file since u cant have 2 public classes in a singlefile.
Next,another error is generated for assigning value to
a final variable.Once final variable is initialised,
it cant be assigned again.
 
Ranch Hand
Posts: 213
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You will get one more error: you cannot access instance variable c from within a static method main.
 
reply
    Bookmark Topic Watch Topic
  • New Topic