IN Java: Will the following code work? * b. Why or why not? * c. If it does, wha
ID: 3915329 • Letter: I
Question
IN Java: Will the following code work? * b. Why or why not? * c. If it does, what will the following code display? * --------------------------------------------------------------------------------------------------------- * public class MyClass{ int x, y, z; public MyClass(int x, int y, int z){ this.x = x; this.y = y; this.z = z; } public int getX(){ return x; } public int getY(){ return y; } public int getZ(){ return z; } public int myFunction(){ int number = getX()*getY()*getZ(); return number; } } public class Main{ public static void main(String[] args){ MyClass myClass = new MyClass(4, 5, 6); int number = myClass.myFunction(); System.out.println(number); } }
Explanation / Answer
Answer:
No you cannot compile public class main and public class MyClass in the same file.
public class main should be a compiled seperately
Or else you will have to program it completely in the public class main. main doesn't support multiple base classes .A program ca only have one base class.
DEAR PLEASE DO RATE IT IF HELPS ELSE LET ME KNOW YOUR DOUBT.
THANK YOU!