Viva Questions For Java Lab
Viva Questions For Java Lab
1) What is Java?
A) Java is an object oriented programming language
4) What is JVM?
A) Java Virtual Machine which accepts java byte code and produces result
Keywords
29) What is keyword?
A) Java reserved word which should is not used as variable/class-name (e.g.:
break, for, if,while etc)
main() method
If the main() method is non-static, then JVM needs to create an instance of the
class, and there would be ambiguity if the constructor of that class takes an
argument – which constructor should be called by JVM and what parameters
should be passed? We know that JVM can’t instantiate a Java class without calling
a constructor method.
No, the main() method must be public. You can’t define the main() method as
private or protected or with no access modifier. This is because to make the main()
method accessible to JVM.
54) Can we declare the main() method as a non-static?
No, the main() method must be declared as static so that JVM can call the main()
method without instantiating its class. If you remove ‘static’ from the main()
method signature, the compilation will be successful but the program fails at
runtime.
56) Can the main() method take an argument other than String array?
No, an argument of the main() method must be a String array. But, from the
introduction of var args, you can pass var args of string type as an argument to
the main() method. Again, var args are nothing but the arrays.
57) Can we run define Java Class without the main() method?
No, We cannot define a class without the main() method.