Sunteți pe pagina 1din 6

Department of Electronics Engineering

OOPM Viva Questions,


Sem-III

Reference questions
1. What is data encapsulation and what’s its significance?
Encapsulation is a concept in Object Oriented Programming for combining properties
and methods in a single unit. Encapsulation helps programmers to follow a modular approach
for software development as each object has its own set of methods and variables and serves
its functions independent of other objects. Encapsulation also serves data hiding purpose.

2. Can we declare the main method of our class as private?


In java, main method must be public static in order to run any application correctly. If
main method is declared as private, developer won’t get any compilation error however, it
will not get executed and will give a runtime error.

3. How can we use primitive data types as objects?


Primitive data types like int can be handled as objects by the use of their respective
wrapper classes. For example, Integer is a wrapper class for primitive data type int. We can
apply different methods to a wrapper class, just like any other object.

4. Can we use a default constructor of a class even if an explicit constructor is


defined?
Java provides a default no argument constructor if no explicit constructor is defined in
a Java class. But if an explicit constructor has been defined, default constructor can’t be
invoked and developer can use only those constructors which are defined in the class.

5. Is JDK required on each machine to run a Java program?


JDK is development Kit of Java and is required for development only and to run a
Java program on a machine, JDK isn’t required. Only JRE is required.

6. What are Java Packages? What’s the significance of packages?


In Java, package is a collection of classes and interfaces which are bundled together
as they are related to each other. Use of packages helps developers to modularize the code
and group the code for proper re-use. Once code has been packaged in Packages, it can be
imported in other classes and used.

7. Does Importing a package imports its sub-packages as well in Java?


In java, when a package is imported, its sub-packages aren’t imported and developer
needs to import them separately if required. For example, if a developer imports a package
university.*, all classes in the package named university are loaded but no classes from the
sub-package are loaded. To load the classes from its sub-package ( say department),
developer has to import it explicitly as follows:

Import university.department.*;

8. Is it compulsory for a Try Block to be followed by a Catch Block in Java for


Exception handling?
Try block needs to be followed by either Catch block or Finally block or both. Any
exception thrown from try block needs to be either caught in the catch block or else any
specific tasks to be performed before code abortion are put in the Finally block.

Prof. Vaishali Patil,


ETRX dept.
Department of Electronics Engineering
OOPM Viva Questions,
Sem-III

9. Is there any way to skip Finally block of exception even if some exception occurs in
the exception block?
If an exception is raised in Try block, control passes to catch block if it exists otherwise
to finally block. Finally block is always executed when an exception occurs and the only way
to avoid execution of any statements in Finally block is by aborting the code forcibly by
writing following line of code at the end of try block:

10. How destructors are defined in Java?


In Java, there are no destructors defined in the class as there is no need to do so. Java
has its own garbage collection mechanism which does the job automatically by destroying the
objects when no longer referenced.

11. What will be the output of following piece of code?


public class operatorExam
ple {
public static void main(String args[]) {
int x=4;
System.out.println(x++);
}
}
12. Can we call a non-static method from inside a static method?
Non-Static methods are owned by objects of a class and have object level scope and in
order to call the non-Static methods from a static block (like from a static main method), an
object of the class needs to be created first. Then using object reference, these methods can be
invoked.

13. I want my class to be developed in such a way that no other class (even derived
class) can create its objects. How can I do so?
If we declare the constructor of a class as private, it will not be accessible by any
other class and hence, no other class will be able to instantiate it and formation of its object
will be limited to itself only.

14. What happens if an exception is not handled in a program?


If an exception is not handled in a program using try catch blocks, program gets
aborted and no statement executes after the statement which caused exception throwing.

15. What is the difference between error and an exception?


An error is an irrecoverable condition occurring at runtime. Such as OutOfMemory
error. Exceptions are conditions that occur because of bad input etc. e.g.
FileNotFoundException will be thrown if the specified file does not exist.

16. Can you give few examples of final classes defined in Java API?
java.lang.String, java.lang.Math are final classes.

17. Can we declare a static variable inside a method?


Static varaibles are class level variables and they can't be declared inside a method. If
declared, the class will not compile.

Prof. Vaishali Patil,


ETRX dept.
Department of Electronics Engineering
OOPM Viva Questions,
Sem-III

18. Can a abstract class be declared final?


Not possible. An abstract class without being inherited is of no use and hence will
result in compile time error.

19. What is use of a abstract variable?


Variables can't be declared as abstract. only classes and methods can be declared as
abstract.

20. Can a abstract class be defined without any abstract methods?


Yes it's possible. This is basically to avoid instance creation of the class.

21. Class C implements Interface I containing method m1 and m2 declarations.


Class C has provided implementation for method m2. Can we create an object of
Class C?
No not possible. Class C should provide implementation for all the methods in the
Interface I. Since Class C didn't provide implementation for m1 method, it has to be
declared as abstract. Abstract classes can't be instantiated.

22. Can a method inside a Interface be declared as final?


No not possible. Doing so will result in compilation error. public and abstract are the
only applicable modifiers for method declaration in an interface.

23. Why is an Interface be able to extend more than one Interface but a Class can't
extend more than one Class?
Basically Java doesn't allow multiple inheritance, so a Class is restricted to extend
only one Class. But an Interface is a pure abstraction model and doesn't have
inheritance hierarchy like classes(do remember that the base class of all classes is
Object). So an Interface is allowed to extend more than one Interface.

24. Why is java architectural neutral?


25. List features of java.
26. Which Java operator is right associative?
27. Why java is considered dynamic?
28. List keywords in java.
29. Define class?
30. Name the eight primitive Java types.
31. What is casting?
32. Can a for statement loop indefinitely?
33. What is local variable?
34. Are true and false keywords?
35. According to Java Operator precedence, which operator is considered to be with
highest precedence?
36. What is default value of byte data type in java?
37. What are order of precedence and associativity, and how are they used?
38. How many bits are used to represent Unicode, ASCII characters?
39. Is null a keyword?
40. Is sizeof a keyword?

Prof. Vaishali Patil,


ETRX dept.
Department of Electronics Engineering
OOPM Viva Questions,
Sem-III

41. Can variables be used in Java without initialization?


42. What happens when you add a double value to a String?
43. To what value is a variable of the String type automatically initialized?
44. What is the difference between the >> and >>> operators?
45. Explain different operators in java.
46. What are bitwise operators?
47. What restrictions are placed on the values of each case of a switch statement?
48. What is the range of the char, short, long, int, byte, Boolean, float double data types?
49. What’s the purpose of Static methods and static variables?
50. What is the difference between a while statement and a do while statement?
51. Can a variable be local and static at the same time?
52. What is Polymorphism?
53. Is the ternary operator written as x : y ? z or x ? y : z ?
54. What is the % operator?
55. What is Abstraction?
56. What is Encapsulation?
57. Does a class inherit the constructors of its superclass?
58. Can we have static methods in an Interface?
59. Does Java support multiple inheritance?
60. What are the various access specifiers for Java classes?
61. What is protected access specifier?
62. What are Loops in Java? What are three types of loops?
63. What is the difference between con
64. Which object oriented Concept is achieved by using overloading and overriding?
65. Explain continue and break statement?
66. What are data types in java?
67. What is the difference between an if statement and a switch statement?
68. How is final different from finally and finalize()?
69. I want to print "Hello" even before main() is executed. How will you achieve that?
70. Can we have any other return type than void for main method?
71. What is Final Keyword in Java?
72. What is ternary operator?
73. Variable of the boolean type is automatically initialized as?
74. What is the difference between a constructor and a method?
75. Give an example of use of Pointers in Java class.
76. Explain syntax of Switch case.
77. What is the difference between a static and a non-static inner class?
78. Can we cast any other data type to Boolean Type with type casting?
79. What’s the purpose of using Break in each case of Switch Statement?
80. Can main() method in Java can return any data?
81. What is an abstract class?
82. What is the difference between method overriding and overloading?
83. Can a method be overloaded based on different return type but same argument type ?

Prof. Vaishali Patil,


ETRX dept.
Department of Electronics Engineering
OOPM Viva Questions,
Sem-III

84. What are the practical benefits, if any, of importing a specific class rather than an
entire package (e.g. import java.net.* versus import java.net.Socket ?
85. Can a Byte object be cast to a double value?
86. What is the difference between a public and a non-public class?
87. Can a method inside a Interface be declared as final?
88. Can an Interface implement another Interface?
89. Can a Class extend more than one Class?
90. Can we declare a class as Abstract without having any abstract method?
91. What’s the difference between an Abstract Class and Interface in Java?
92. When the constructor of a class is invoked?
93. Can a class have multiple constructors?
94. What’s the default access specifier for variables and methods of a class?
95. How objects of a class are created if no constructor is defined in the class?
96. Can we call the constructor of a class more than once for an object?
97. Can we override static methods of a class?
98. Can a constructor have different name than a Class name in Java?
99. What is the access scope of a protected method?
100. In a class implementing an interface, can we change the value of any variable
defined in the interface?
101. Can an Interface be final?
102. What is the purpose of declaring a variable as final?
103. What is the impact of declaring a method as final?
104. I don't want my class to be inherited by any other class. What should i do?
105. What is finalize() method?
106. When throws keyword is used?
107. How can we restrict inheritance for a class so that no class can be inherited from it?
108. Is String a data type in java?
109. What is the argument of main() method?
110. How garbage collection is done in Java?
111. When super keyword is used?
112. There are two classes named class A and class B. Both classes are in the same
package. Can a private member of class A can be accessed by an object of classB?
113. Why Strings in Java are called as Immutable?
114. Which package is imported by default?
115. Can a class be a super class and a sub-class at the same time? Give example.
116. What is multi-threading?
117. In Java thread programming, which method is a must implementation for all
threads?
118. Describe different states of a thread.
119. How we can execute any code even before main method?
120. Why Runnable Interface is used in Java?
121. What are the two ways of implementing multi-threading in Java?
122. Can we have two methods in a class with the same name? Explain.

Prof. Vaishali Patil,


ETRX dept.
Department of Electronics Engineering
OOPM Viva Questions,
Sem-III

123. What’s the benefit of using inheritance?


124. Can a dead thread be started again?
125. Can a class in Java be inherited from more than one class?
126. Is there a way to increase the size of an array after its declaration?
127. What’s the base class of all exception classes?
128. What’s the order of call of constructors in inheritiance?
129. What is an applet?
130. An applet extend which class?
131. Difference between Overloading and Overriding?
132. What is final class?
133. List few methods of multithreading?
134. List methods used in applet?

Prof. Vaishali Patil,


ETRX dept.

S-ar putea să vă placă și