Core Java - Interview Questions and Answers for 'Classe' | 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
 Q31. Explain about anonymous inner classes ?Core Java
Ans. Anonymous classes are defined in the new expression itself, so you cannot create multiple objects of an anonymous class.

You cannot explicitly extend a class or explicitly implement interfaces when defining an anonymous class.

An anonymous inner class is always created as part of a statement; don't forget to close the statement after the class definition with a curly brace. This is a rare case in Java, a curly brace followed by a semicolon.

Anonymous inner classes have no name, and their type must be either a subclass of the named type or an implementer of the named interface

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

   Like         Discuss         Correct / Improve     java   oops   inner classes   anonymous inner classes   classes     Asked in 1 Companies


 Q32. Can we compare Integers by using equals() in Java ?Core Java
Ans. Yes for the Wrapper class Integer but not for the primitive int.

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

   Like         Discuss         Correct / Improve     java   wrapper classes   equals


 Q33. Can we declare Entity class as final ?Hibernate
Ans. Yes but as Hibernate creates the Proxy Classes inherited from the Entity Classes to communicate with Database for lazy initialization. Declaring entity classes as final will prohibit communication with database lazily and hence will be a performance hit.

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

   Like         Discuss         Correct / Improve     hibernate   proxy objects   proxy classes   entity hibernate


 Q34. What will the following code do ?

String dateStr = "2011 11 19";
DateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd");
Date date = dateFormat.parse(dateStr);
System.out.println(date);

Ans. It will throw the ParseException as the date format doesn't abide with the format of the specified date.

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

   Like         Discuss         Correct / Improve     date   utility classes   dateformat   exception   parseexception


 Q35. Is this valid in Java ?

Long x = new Long ("42");
Core Java
Ans. Yes. Long wrapper class has overloaded constructor which takes String as input and then translate it to the long value and stored it as long.

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

   Like         Discuss         Correct / Improve     java   wrapper classes   long wrapper class   long


 Q36. Will this Code compile ?

abstract public class BuggyBread1{
abstract public void test(){};
}
Core Java
Ans. No. This will give a compilation error saying "Abstract methods do not specify a body".

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

   Like         Discuss         Correct / Improve     java   abstract classes   abstract methods   java compilation error   java coding   java code   coding   yes-no


 Q37. Can we have multiple classes in single file ?
Ans. Yes, but there can be only 1 public class in a single file.

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

   Like         Discuss         Correct / Improve     java   classes


 Q38. 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


Must know at all levels. Among Top 10 frequently asked questions in Java. Very frequently asked to fresh graduates or less experienced professionals.
  Q39. 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


 Q40. 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


 Q41. 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


 Q42. 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


 Q43. 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


 Q44. 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


 Q45. 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


 Q46. 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


 Q47. 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


 Q48. 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


 Q49. 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


 Q50. What are Util Classes ? What are its advantages ?Core Java
Ans. Classes having only static methods in java is called util classes. As they don't have specific object state, they are basically intend to have shared code and state through static elements and methods. They save resources by sharing code.

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

   Like         Discuss         Correct / Improve     util classes

Try 1 Question(s) Test


 Q51. What is Boxing conversion ?Core Java
Ans. Boxing conversion converts expressions of primitive type to corresponding expressions of reference type.

For example

boolean to Boolean
long to Long
double to Double

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

   Like         Discuss         Correct / Improve     data type  boxing  wrapper classes


 Q52. Can we declare a class private ?Core Java
Ans. We can declare an inner class as private and hence would be restricting it's access from outside. We cannot make outer class as private.

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

   Like         Discuss         Correct / Improve     private class   inner classes  nested classes


 Q53. How can we hide a class in Java ?Core Java
Ans. By encapsulating it within another class and declaring it private. In such a case, it will only be accessible through parent class or parent class object.

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

   Like         Discuss         Correct / Improve     private class   private inner class  class hiding  encapsulation  object oriented programming (oops)  oops concepts  inner classes   nested classes


 Q54. Can an inner class be subclass of it's parent class ?Core Java
Ans. Yes that can be done

public class OuterClass {
public class InnerClass extends OuterClass {
}
}

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

   Like         Discuss         Correct / Improve     inner classes  nested classes  sub class      Basic


 Q55. Is this code legal in java i.e nested class within interface implementing the parent interface ?

public interface MyInterface {
public class MyClass implements MyInterface {
}
}
Core Java
Ans. Yes that's legal in java

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

   Like         Discuss         Correct / Improve     inner classes  nested classes  sub class      Basic


 Q56. Can an interface be defined inside a class just like we can have inner classes inside a class ?Core Java
Ans. Yes , we can have an interface that is part of a class.

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

   Like         Discuss         Correct / Improve     inner classes   inner interface  nested classes


 Q57. Does Wrapper classes produces immutable objects ? Core Java
Ans. Yes

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

   Like         Discuss         Correct / Improve     wrapper classes  immutable  immutability


 Q58. What are the advantage of Abstract classes over interfaces with respect to Java 7 ? and What changed in Java 8 to help facilitate that in Java 8 ?Core Java
Ans. Abstract Classes provide default implementations of methods that are inherited by the classes that extend them, which was not the case for Interfaces. This changed in Java 8, where default implementations are provided for methods.

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

   Like         Discuss         Correct / Improve     abstract classes  interfaces  default method     Asked in 1 Companies      expert


 Q59. Why can we have a static inner class but not a static Top level class in Java ?Core Java
 This question is still unanswered. Can you please provide an answer.


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

   Like         Discuss         Correct / Improve     static class  inner classes   nested classes      Expert        rare


 Q60. Can we use primitive types with Collection classes ?Core Java
Ans. No, As collection classes involve use of Generics, they cannot accept primitive types.

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

   Like         Discuss         Correct / Improve     collection classes  collections


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: