What Will Be The Output Of The Following Java Codep Pre #472
What will be the output of the following Java code?</p> <pre><code class="language-java"> class Area { int side; public int squareArea() { int a = this.side * this.side; return a; } } public class InstanceVariables { public static void main(String[] args) { Area a = new Area(); System.out.println("Area: "+a.squareArea()); } } </code></pre>
This multiple choice question (MCQ) is related to the book/course gs gs111 OOP Object Oriented Programming Java. It can also be found in gs gs111 Class Components (Using Java) - Data Members - Quiz No.1.
What will be the output of the following Java code?
class Area { int side; public int squareArea() { int a = this.side * this.side; return a; } } public class InstanceVariables { public static void main(String[] args) { Area a = new Area(); System.out.println("Area: "+a.squareArea()); } }
Initialize instance variables before use
Compilation error
Area: 0
Runtime error