Win a copy of Programmer's Guide to Java SE 8 Oracle Certified Associate (OCA) this week in the OCAJP forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

interface variable must be initialized ?

 
Harikrishna Gorrepati
Ranch Hand
Posts: 423
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
interface P00_Constructor5_Ask
{
int answer; //The blank final field answer may not have been initialized..Why not taking default value ?
}
 
Ankit Garg
Sheriff
Posts: 9527
32
Android Google Web Toolkit Hibernate IntelliJ IDE Java Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
final fields don't get a default value, you have to assign them a value explicitly...
 
Harikrishna Gorrepati
Ranch Hand
Posts: 423
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Got it..thanks Ankit
 
Arjun Srivastava
Ranch Hand
Posts: 432
Eclipse IDE Firefox Browser Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
final variables must be initialize on the same line or at the end of constructor.
because interface cannot have constructors so final variables have to be initialize on the same line on which it is being declared.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic