Interview Questions and Answers for 'Cla' | Search Interview Question - javasearch.buggybread.com
Javasearch.buggybread.com

Search Interview Questions


 More than 3000 questions in repository.
 There are more than 900 unanswered questions.
Click here and help us by providing the answer.
 Have a video suggestion.
Click Correct / Improve and please let us know.
Label / Company      Label / Company / Text

   



Interview Questions and Answers - Order By Newest

   next 30
 Q131. Which of the following is not type of inner classes ?

a. Simple Inner Class
b. Static Nested Inner Class
c. Method Nested Static Inner Class
d. Anonymous Inner Class
Ans. Method Nested Static Inner Class

 Help us improve. Please let us know the company, where you were asked this question :   

   Like         Discuss         Correct / Improve     java   classes   inner classes

Try 1 Question(s) Test


 Q132. Which of the following is not the difference between Singleton and Static class ( Class with static members only ) ?

a. Only one object can be created for Singleton class whereas No objects are created for static class.
b. Singleton class instance is initiated using new keyword whereas static class instance is created using static method.
c. Singleton class can be serialized whereas Static class cannot be.
d. Singleton Class can participate in runtime Polymorphism whereas Static class cannot.
Ans. Singleton class instance is initiated using new keyword whereas static class instance is created using static method.

 Help us improve. Please let us know the company, where you were asked this question :   

   Like         Discuss         Correct / Improve     java   oops   singleton   design pattern   static class


 Q133. Which of the following do you think is the primary reason you would never use a static class even the application doesn't need multiple requests or threads ?

a. Serialization
b. Runtime Polymorphism
c. Lazy Loading
d. Memory
Ans. Runtime Polymorphism

 Help us improve. Please let us know the company, where you were asked this question :   

   Like         Discuss         Correct / Improve     static class   static vs singleton   java   oops   objects  Runtime Polymorphism


Must know at all levels. Among Top 10 frequently asked questions in Java. Very frequently asked to fresh graduates or less experienced professionals.
  Q134. What is Inheritance ?Core Java
Ans. Its a facility for code reuse and independent extension wherein a derived class inherits the properties of parent class.

 Help us improve. Please let us know the company, where you were asked this question :   

   Like         Discuss         Correct / Improve     inheritance  object oriented programming (oops)  oops concepts  oops concepts  java concepts  code reuse  code re-use   classes  derived classes     Asked in 14 Companies      basic        frequent


 Q135. What is a Java Bean ? How is it different from other Java classes ?
Ans. A Java bean is a class which abides by following conventions:

Core of the object is member elements and not operations ( methods )

Member Elements can be accessed by getters (and setters if those properties are not read-only).

serializable.

 Help us improve. Please let us know the company, where you were asked this question :   

   Like         Discuss         Correct / Improve     java bean   javabean   pojo   classes      basic        frequent


 Q136. In the following code , how many methods needs to be implemented in Class B ?

public interface A{
   public void method1();
   public void method2();
   public void method3();
}

abstract class B implements A{
}
Core Java
Ans. As Class B has been declared abstract , we can either implement any of these methods and just declare rest of them abstract.

 Help us improve. Please let us know the company, where you were asked this question :   

   Like         Discuss         Correct / Improve     interfaces  abstract classes  code  coding

Try 2 Question(s) Test


 Q137. Can a lock be acquired on a class? How is it different than the object level lock ?
Ans. Yes, a lock can be acquired on the class. Class level lock is applicable on the whole class and hence on all objects of the class whereas the object level lock is applicable on the respective object.

 Help us improve. Please let us know the company, where you were asked this question :   

   Like         Discuss         Correct / Improve     synchronization  class level lock  object level lock


 Q138. What is the use of Runtime Class ?
Ans. This class is used to provide access to the Java runtime system

 Help us improve. Please let us know the company, where you were asked this question :   

   Like         Discuss         Correct / Improve     runtime class  jre  java runtime


 Q139. What should a class do if its extending an abstract class ?Core Java
Ans. It should either implement the abstract methods or re-declare them abstract.

 Help us improve. Please let us know the company, where you were asked this question :   

   Like         Discuss         Correct / Improve     abstract class     Asked in 2 Companies      Basic        Frequent


 Q140. What is the use of Combiners ?BigData
Ans. Combiners are used to increase the efficiency of a Map Reduce program. They are used to aggregate intermediate map output locally on individual mapper outputs. Combiners can help you reduce the amount of data that needs to be transferred across to the reducers.

 Help us improve. Please let us know the company, where you were asked this question :   

   Like         Discuss         Correct / Improve     Hadoop Systems  BigData   hadoop combiners     Asked in 1 Companies


 Q141. How does the String Class stores the string in memory ?Core Java
Ans. It stores the string as a character array with 2 bytes for each character.

 Help us improve. Please let us know the company, where you were asked this question :   

   Like         Discuss         Correct / Improve     String  String Class


 Q142. Can I run a java program without creating any class ?
Ans. No, It requires creation of atleast one Class. Creating an object of that class is not compulsory as we can write all our logic within main method which is static.

 Help us improve. Please let us know the company, where you were asked this question :   

   Like         Discuss         Correct / Improve     java program without creating any class


 Q143. What is a static variable in Java ?Core Java
Ans. It is a class level variable that is shared among the objects of that class.

 Help us improve. Please let us know the company, where you were asked this question :   

   Like         Discuss         Correct / Improve     static   static variables   class level variables     Asked in 1 Companies      basic        frequent

Try 1 Question(s) Test


 Q144. Can we access private members of the parent class ? i.e Are private members of the class visible in the derived class ?Core Java
Ans. No, If both Parent and Derived are outer classes.

public class Vehicle {
private static String manufacturingDate = "2016";
}

public class Car extends Vehicle{
public static void main(String args[]){
System.out.println(manufacturingDate); // error - The field Vehicle.manufacturingDate is not visible
}
}

Yes, If derived is the inner class of Parent.

public class Vehicle {
private static String manufacturingDate = "2016";
static public class Car extends Vehicle{
public static void main(String args[]){
System.out.println(manufacturingDate); // no problem
}
}
}

 Help us improve. Please let us know the company, where you were asked this question :   

   Like         Discuss         Correct / Improve     private members   private methods   private variables   inheritance  object oriented programming (oops)  oops concepts   members visibility   inner classes  nexted classes      basic        frequent


 Q145. What is a classpath in Java ?Core Java
Ans. Classpath is the parameter for JVM to look for java classes ( .class files ) that are to be looad by class loader

 Help us improve. Please let us know the company, where you were asked this question :   

   Like         Discuss         Correct / Improve     classpath     Asked in 1 Companies      basic


 Q146. Write a class explaining builder pattern ?Design
Ans.
public class BuggyBread { 

private String element1;

private String element2;

private BuggyBread(String element1, String element2){
this.element1 = element1;
this.element2 = element2;
}

public static class Builder {

private String element1;

private String element2;

Builder(BuggyBread buggybread){
element1 = buggybread.element1;
element2 = buggybread.element2;
}

Builder withElement1(String element1){
this.element1 = element1;
return this;
}

Builder withElement2(String element2){
this.element2 = element2;
return this;
}

BuggyBread build(){
BuggyBread buggybread = new BuggyBread(element1,element2);
return buggybread;
}
}
}


 Help us improve. Please let us know the company, where you were asked this question :   

   Like         Discuss         Correct / Improve     builder pattern  builder class

Try 1 Question(s) Test


 Q147. Have you heard of Ban Duplicate Classes Maven enforcer plugin ? What is its use ?Maven
Ans. Yes , we have been using this plugin with our projects and its purpose is to warn and stop the Build if there are duplicates of the same package and class are being carried either directly or through transitive dependencies. the duplicate could be coming through different types of dependencies or through different versions of the same dependency. Its purpose is to make sure that there is only one copy thats being used at compile time and runtime and hence shouldnt later result in runtime problems.

 Help us improve. Please let us know the company, where you were asked this question :   

   Like         Discuss         Correct / Improve     maven   ban duplicate classes enforcer plugin


 Q148. How to tackle duplicate classes in maven build ?Maven
Ans. The simplest way is to ignore them if Maven enforcer plugin is complaining about it but it may lead to runtime problems later.

We can do the dependency:tree to see from where these duplicate ones are coming and hence can exclude the duplicate one.

 Help us improve. Please let us know the company, where you were asked this question :   

   Like         Discuss         Correct / Improve     maven   ban duplicate classes enforcer plugin


 Q149. Can we have an inner class within Interface ?Core Java
Ans. Yes, we can define an inner class within interface.Inside the interface, the inner class is implicitly public static.

So the following is legit in Java

public interface BuggyBreadInterface {
   void doSomething();

   public class BuggyBreadClass implements BuggyBreadInterface{
      void doSomething(){
         System.out.println("Do something");
      }
   }
}

 Help us improve. Please let us know the company, where you were asked this question :   

   Like         Discuss         Correct / Improve     inner classes  inner class in interface  nested classes


 Q150. Difference between System.out.printf and System.out.println ?Core Java
Ans. println prints an additional end of line whereas printf doesnt.

 Help us improve. Please let us know the company, where you were asked this question :   

   Like         Discuss         Correct / Improve     System class  Streams  Input Output  println  printf


 Q151. What is meant by following error ?

Source folder is not on the Java build class path
Core Java
Ans. It means that the respective folder is not looked upon by Java to look for java or resource files and hence not being included as part of build.It needs to be added to Java Build Path.

 Help us improve. Please let us know the company, where you were asked this question :   

   Like         Discuss         Correct / Improve     build path.build class path


 Q152. How is String class unique ?Core Java
Ans. String class is immutable as well as final. Because of these properties , String objects offer many benefits

1. String Pool - When a string is created and if it exists in the pool, the reference of the existing string will be returned instead of creating a new object. If string is not immutable, changing the string with one reference will lead to the wrong value for the other references.

Example -

String str1 = "String1";
String str2 = "String1"; // It doesnt create a new String and rather reuses the string literal from pool

// Now both str1 and str2 pointing to same string object in pool, changing str1 will change it for str2 too

2. To Cache its Hashcode - If string is not immutable, One can change its hashcode and hence its not fit to be cached.

3. Security - String is widely used as parameter for many java classes, e.g. network connection, opening files, etc. Making it mutable might possess threats due to interception by the other code segment.

 Help us improve. Please let us know the company, where you were asked this question :   

   Like         Discuss         Correct / Improve     immutable  immutability  immutability  String  string class     Asked in 1 Companies


 Q153. Which method of String class is used to convert Boolean to String ?Core Java
Ans. toString() is an overloaded method of String class that is used to convert many data types to String, Boolean being one of them.

toString(Boolean bool)

 Help us improve. Please let us know the company, where you were asked this question :   

   Like         Discuss         Correct / Improve     String  String class  Boolean     Asked in 1 Companies      Basic


 Q154. What are Collection Classes ?Core Java
Ans. Collections in java is a framework of classes that provides an abstracted data structure to store and manipulate the group of objects. Each class is unique in the way it stores , search , sort and modify the elements.

 Help us improve. Please let us know the company, where you were asked this question :   

   Like         Discuss         Correct / Improve     collections  collection classes     Asked in 1 Companies      Basic        frequent


 Q155. When should we use Abstract classes ?Core Java
Ans. Abstract classes provide a mechanism of interfacing ( using abstract method ) as well as inheritance ( extending abstract class ). So they should be used in place of interfaces in case there is some code ( methods ) or object body ( member elements ) that can be reused with inheritance.

 Help us improve. Please let us know the company, where you were asked this question :   

   Like         Discuss         Correct / Improve     abstract classes     Asked in 1 Companies


 Q156. What will be the output of following code

public class BuggyBread {
   static class A {
      A() {
         f();
      }

      public void f() {
         System.out.println("A ctor");
      }
   }

   static class B extends A {
      B() {
         f();
      }

      public void f() {
         System.out.println("B ctor");
      }
   }

   public static void main(String[] args) {
      B b = new B();
      b.f();
      A a = new A();
      a.f();
   }
}
Core Java
Ans. B ctor
B ctor
B ctor
A ctor
A ctor

 Help us improve. Please let us know the company, where you were asked this question :   

   Like         Discuss         Correct / Improve          Asked in 1 Companies


 Q157. Which environment variables do we need to set in order to run Java programs?Core Java
Ans. PATH, CLASSPATH and JAVA_HOME

 Help us improve. Please let us know the company, where you were asked this question :   

   Like         Discuss         Correct / Improve     environment variables  path  classpath  java_home     Asked in 3 Companies      basic        frequent


 Q158. how to access the methods of an inner class?Core Java
Ans. It depends on the type of inner class

To access non static inner class method

new OuterClass().new InnerClass().getMethod();

To access static method of static inner class

new OuterClass.InnerClass().getMethod();

  Sample Code for inner class

 Help us improve. Please let us know the company, where you were asked this question :   

   Like         Discuss         Correct / Improve     inner classes  nested aclasses     Asked in 1 Companies      Intermediate        frequent


 Q159. What is a class and object ?

or

How would you explain a fresher the concept of class and object in simple terms ?
Core Java
Ans. Class is a template using which objects are created in memory. It's kind of a mold using which objects with body / state are made.


 Help us improve. Please let us know the company, where you were asked this question :   

   Like         Discuss         Correct / Improve     class  object  class vs object     Asked in 4 Companies      basic        frequent


 Q160. Upon compiling the following class, What .class files will get created

public class OuterClass{
class InnerClass{
}
}
Core Java
Ans. OuterClass.class AND OuterClass$InnerClass.class

 Help us improve. Please let us know the company, where you were asked this question :   

   Like         Discuss         Correct / Improve     class files  compilation  compile  inner classes   nested classes


previous 30   next 30

Help us and Others Improve. Please let us know the questions asked in any of your previous interview.

Any input from you will be highly appreciated and It will unlock the application for 10 more requests.

Company Name:
Questions Asked: