0% found this document useful (0 votes)
13 views

Viva Questions For Java Lab

Uploaded by

Megha Kulkarni
Copyright
© © All Rights Reserved
Available Formats
Download as DOC, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
13 views

Viva Questions For Java Lab

Uploaded by

Megha Kulkarni
Copyright
© © All Rights Reserved
Available Formats
Download as DOC, PDF, TXT or read online on Scribd
You are on page 1/ 6

JAVA VIVA QUESTIONS

1) What is Java?
A) Java is an object oriented programming language

2) Is Java invented for Internet?


A) No, it was developed for programming towards tiny devices

3) What is byte code?


A) It is machine understandable code and targeted for JVM (Java Virtual
Machine). It is class file.

4) What is JVM?
A) Java Virtual Machine which accepts java byte code and produces result

5) What are java buzzwords?


A) Java buzzwords explain the important features of java. They are Simple,
Secured, Portable, architecture neutral, high performance, dynamic, robust,
interpreted etc.

6) Is byte code is similar to .obj file in C?


A) Yes, both are machine understandable codes
No, .obj file directly understood by machine, byte code requires JVM

7) What is new feature in control statements comparing with C/C++? A)


Labeled break and labeled continue are new

8) What are new features in basic features comparing with C/C++? A)


Data types: All data types on all machines have fixed size; Constants: final
is used to declare constant
Boolean Type: boolean is new data type in Java which can store true/falseThere are
no structures/unions/pointers

9) Is String data type?


A) No, Strings are classes in Java (Arrays are classes)
10) What are length and length( ) in Java?
A) Both gives number of char/elements, length is variable defined in Array class,
length( ) is method defined in String class Object-Orientation Section

11) What is class?


A) Class is blue print for objects; Class is collection of objects; Class gives the
generalstructure for objects.
12) What is object?

Prepared By:Prof Megha S Kulkarni Page 1


JAVA VIVA QUESTIONS
A) Object is an instance of class. Object is real world entity which has state,
identity and behavior.

13) What is encapsulation?


A) Encapsulation is packing of data with their methods

14) What is abstraction?


A) Abstraction is the process of identification of essential features of objects

15) What is data hiding?


A) Implementation details of methods are hidden from the user

16) What is hierarchy?


A) Ordering of classes (or inheritance)

17) What is inheritance?


A) Extending an existing class is called inheritance. Extracting the features of
super class

18) Why inheritance is important?


A) Reusability is achieved through inheritance

19) Which types of inheritances are available in Java?


A) Simple, Hierarchical and Multilevel

20) Can we achieve multiple inheritances in Java?


A) With the help of interfaces we can achieve
21) What is interface?
A) Interface is collection of final variables and abstract methods
(We need not give final and abstract keywords and By default they are public
methods)

22) What is the difference between class and interface?


A) Class contains implemented methods, but interface contains non-implemented
methods

23) What is polymorphism?


A) Multiple (poly) forms (morphs) same instance can respond different manners is
called polymorphism

24) Can we achieve run time polymorphism in Java?

Prepared By:Prof Megha S Kulkarni Page 2


JAVA VIVA QUESTIONS
A) Yes, also called as dynamic polymorphism. Possible by dynamic method
dispatch

25) What is dynamic method dispatch?


A) When you assign object of sub class for the super class instance, similar
methods of super class are hidden

26) What is overloading?


A) Same method name can be used with different type and number of arguments
(in same class)

27) What is overriding?


A) Same method name, similar arguments and same number of arguments can
be
defined in super class and sub class. Sub class methods override the super class
methods.

28) What is the difference between overloading and overriding?


A) Overloading related to same class and overriding related sub-super class
Compile time polymorphism achieved through overloading, run time
polymorphism achieved through overriding

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)

30) What is final keyword?


A) Used before variables for declaring constants Used
before methods for preventing from overriding Used before
class-name for preventing from inheritance

31) What is static keyword?


A) Used before variable for defining shared variables
Used before method for defining class-level methods, these methods
Can be called without creating objects (e.g.: parseInt method of Integer class)

32) What is abstract keyword?


A) Used for creating abstract class, class which doesn't have any instance

33) What is this keyword?


A) To call current class variables and current class methods we can use this key
word
Prepared By:Prof Megha S Kulkarni Page 3
JAVA VIVA QUESTIONS

34) What is this( )?


A) Used for calling another constructor of current class

35) What is super keyword?


A) To call super class variables and super class methods we can use super key
word

36) What is super( )?


A) Used for calling of super class constructor and it should be first executable
statement insub class constructor

Packages and Exception handling section


37) What is package?
A) Package is collection of classes and interfaces

38) How to define package?


A) By using package keyword before the definition of class

39) What is CLASSPATH?


A) It is an environment variable which is used for defining the location of class
files

40) What is jar?


A) Jar stands for Java archive files, compressed set of class files and can be used in
CLASSPATH

41) What is the meaning of import java.awt.*;?


A) Import all the classes and interfaces in the java.awt.package. This doesn't
imports other packages
defined in java.awt. package.

42) Is it necessary to give import java.awt.event.*;, when already import


java.awt.* given?
A) Yes, import java.awt.* doesn't imports event package defined in java.awt.
package.

43) What is exception?


A) Abnormal termination of program is called exception

44) What is exception handler?


A) A method which controls abnormal termination of program

Prepared By:Prof Megha S Kulkarni Page 4


JAVA VIVA QUESTIONS

45) What are the keywords used for exception handling? A)


try, catch, throw, throws and finally
46) What is the difference between throw and throws keywords? A)
throw keyword is used for invoking an exception (For raising)
throws keyword lists exception names which can be ignored from the method
execution

47) What is the difference between final and finally?


A) final is used for defining constants
finally is used for executing code after completion of exception handler

48) What is catch( ) block?


A) Exception handler that controls abnormal termination of program

49) Can we have multiple catch( ) blocks?


A) Yes, but first sub class exceptions should be handled

50) What happen is we not handle sub class exception first?


A) Generates compile time error saying that unreachable code is defined in the
program

main() method

51)Why the main() method is public static?


First, let's see why the main() method is static in Java?
The main() method is static in Java, so the JVM can directly invoke it without
instantiating the class’s object.

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.

52) Can we overload the main() method in Java?


Yes, We can overload the main() method. A Java class can have any number of
main() methods. But to run the java class, the class should have a main() method
with signature as public static void main(String[] args).

53) Can we declare the main() method as private or protected or with no


access modifier?
Prepared By:Prof Megha S Kulkarni Page 5
JAVA VIVA QUESTIONS

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.

55) Can we change the return type of the main() method?


No, the return type of the main() method must be void only. Any other type is not
acceptable.

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.

58) Can we make the main final in Java?


Yes, you can make the main() method final.

Prepared By:Prof Megha S Kulkarni Page 6

You might also like