JAVA Ques
JAVA Ques
Roll No. –
Stream –
Q2. What are the various access specifiers for Java classes?
Ans:
Q3. What's the purpose of Static methods and static variables?
Ans:
Q6. What are Loops in Java? What are the three types of loops?
Ans:
Q7: What is an infinite Loop? How infinite loop is declared?
Ans:
Q14. What's the base class in Java from which all classes are derived?
Ans:
Q18. What’s the difference between an Abstract Class and Interface in Java?
Ans:
Q19. What are the performance implications of Interfaces over abstract classes?
Ans:
Q26. Is there any way to skip Finally block of exception even if some exception occurs
in the exception block?
Ans:
Q27. When the constructor of a class is invoked?
Q32. In the below example, how many String Objects are created?
String s1="I am Java Expert";
String s2="I am C Expert";
String s3="I am Java Expert";
Ans:
Q39. What's the purpose of using Break in each case of Switch Statement?
Ans:
Q42. Can a class be a super class and a sub-class at the same time? Give example.
Ans:
Q43. How objects of a class are created if no constructor is defined in the class?
Ans:
Q44. In multi-threading how can we ensure that a resource isn't used by multiple
threads simultaneously?
Ans:
Q45. Can we call the constructor of a class more than once for an object?
Ans:
Q46. There are two classes named classA and classB. Both classes are in the same
package. Can a private member of classA can be accessed by an object of classB?
Ans:
Q47. Can we have two methods in a class with the same name?
Ans:
Q48. How can we make a copy of a java object?
Ans:
Q50. What’s the default access specifier for variables and methods of a class?
Ans:
Q51. Give an example of the use of Pointers in Java class.
Ans:
Q52. How can we restrict inheritance for a class so that no class can be inherited from
it?
Ans:
}
}
Ans:
Q62. A person says that he compiled a java class successfully without even having a
main method in it? Is it possible?
Ans:
Ans:
Q64. What are the two environment variables that must be set in order to run any Java
programs?
Ans:
Q65. Can variables be used in Java without initialization?
Ans:
Q66. Can a class in Java be inherited from more than one class?
Ans:
Q67. Can a constructor have a different name than a Class name in Java?
Ans:
Q68. What will be the output of Round (3.7) and Ceil (3.7)?
Ans:
Q69: Can we use goto in Java to go to a particular line?
Ans:
Q72. What's the difference between comparison done by equals method and ==
operator?
Ans:
Q73. Is it possible to define a method in Java class but provide it's implementation in
the code of another language like C?
Ans:
Q74. How are destructors defined in Java?
Ans:
Q78. Is it correct to say that due to garbage collection feature in Java, a java program
never goes out of memory?
Ans:
Q79. Can we have any other return type than void for main method?
Ans:
Q80. I want to re-reach and use an object once it has been garbage collected. How it's
possible?
Ans:
Q81. In Java thread programming, which method is a must implementation for all
threads?
Ans:
Q82. I want to control database connections in my program and want that only one
thread should be able to make database connection at a time. How can I implement
this logic?
Ans:
Q86. How can we find the actual size of an object on the heap?
Ans:
Q87. Which of the following classes will have more memory allocated?
Class A: Three methods, four variables, no object
Class B: Five methods, three variables, no object
Ans:
Q92. If an application has multiple classes in it, is it okay to have a main method in
more than one class?
Ans:
Q93. I want to persist data of objects for later use. What's the best approach to do so?
Ans:
Q97. Can we cast any other type to Boolean Type with type casting?
Ans:
Q98. Can we use different return types for methods when overridden?
Ans:
Q99. What's the base class of all exception classes?
Ans: