Language – Java | Type – Concept | Last date 13-Sep-2009 12:00 p.m. IST | Points 3
Improving upon
last week’s code, I came up with this:
package com.twister; public class Area { //should initialize to 0 - formula mentioned for documentation int area = length*width; //Instance variables get initialized to 0 int length; int width; public static void main(String[] args) { Area a = new Area(); //Do whatever needs to be done in main } }
Now while this is much better than the previous code (no hard coded values, self documenting), I seem to be having a problem with the code. As you might have already guessed this code does not compile!!!
Your challenge is pretty simple – get this code to compile by adding minimum number of characters to this code. Also a few additional conditions that you need to meet are -
a. You may only add code to get this to work – no deletes, no moving about the code, no commenting out any code! Additions only!
b. Obviously
as before, declaring length and width as static would do the trick – but then that is so obvious that it
can’t be the right solution, can it?
(So I am looking for something that solves the problem in less than 12 characters).
Got an answer? Do leave it
here.