Interview Questions and Answers - Order By Rating Recently asked in Capital One. Q1651. What will happen if we call perform(null) ?
public void perform(Object obj) {
System.out.println("Object");
}
public void perform(Integer int) {
System.out.println("Integer");
} Core Java
Ans. compiler will throws error as ambiguous methods Help us improve. Please let us know the company, where you were asked this question : Like Discuss Correct / Improve  overloading   method overloading Asked in 1 Companies intermediate Q1652. How is multiple inheritance implemented in Java ? Core Java
Ans. There was no multiple inheritance in java before version 8 as implementing multiple interfaces cannot be termed as inheritance.
With Java 8 , came the concept of default methods wherein the class implementing the interface carries the default implementation from the interface and hence facilitating multiple inheritance. Help us improve. Please let us know the company, where you were asked this question : Like Discuss Correct / Improve  multiple inheritance  object oriented programming (oops)  oops concepts   inheritance  object oriented programming (oops)  oops concepts   oops concept Asked in 10 Companies   frequent Q1653. In which cases , moving methods to utility class could be useful ? Core Java
Ans. It could be worthy to move a method to util class if the method needs to be shared, doesn't require polymorphic behavior and need not be overridden in special cases.
Don't belong to one group through is-a relationship ( You can share through parent class method )
Don't implement a specific interface ( java 8 default methods )
Doesn't involve complex computing as you will be loosing the benefit of object state with just static method.
Doesn't require polymorphic behavior as static methods don't participate in runtime polymorphism. Help us improve. Please let us know the company, where you were asked this question : Like Discuss Correct / Improve  utility classes   util classes   static methods   application design   rare Q1654. What are the new classes in JDK 1.9 ( Java 9 ) ?
Ans. http://www.buggybread.com/2015/05/java-9-new-classes-and-interfaces-in.html Help us improve. Please let us know the company, where you were asked this question : Like Discuss Correct / Improve  java9  java 9  jdk1.9  jdk 1.9 Q1655. What is a Destructor ? Do we have Destructors in Java ? Core Java
Ans. Destructor is used to de-allocate memory allocated by objects.
There are no destructors in Java. Alternatively, Java provides Automatic garbage collection i.e automatically releasing the un-referenced memory. Help us improve. Please let us know the company, where you were asked this question : Like Discuss Correct / Improve  destructor  garbage collection Asked in 11 Companies Basic   frequent Try 1 Question(s) Test Q1656. Why Java is not considered pure OOP's language ? Core Java
Ans. There are 2 reasons for it.
1. Usage of Primitive types - Though Java provides classes for the primitive data types but as the usage of primitives is permissible, its considered unpure OOP's language.
2. Usage of Static members - Static members belong to the class and not objects and hence not considered fit for pure OOP's programming. Help us improve. Please let us know the company, where you were asked this question : Like Discuss Correct / Improve  oops  object oriented programming  object oriented language  primitive data types Asked in 2 Companies Q1657. 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 runtimeFrequently asked. Q1658. What should a class do if its implementing an interface ? Core Java
Ans. It should either implement all interface methods or declare unimplemented methods as abstract. Help us improve. Please let us know the company, where you were asked this question : Like Discuss Correct / Improve  interfaces Asked in 1 Companies Basic   frequent Try 1 Question(s) Test Q1659. 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 Q1660. What is a compilation unit in Java ?
Ans. Java Source Code File Help us improve. Please let us know the company, where you were asked this question : Like Discuss Correct / Improve  compilation unit in java Q1661. What is Associativity while evaluating a Java statement ? Core Java
Ans. Associativity determines whether an expression is evaluated left-right or right-left. When an expression has two operators with the same precedence, the expression is evaluated according to its associativity. Help us improve. Please let us know the company, where you were asked this question : Like Discuss Correct / Improve  associativity  expression evaluation  operator Q1662. What is a package and what are its advantages ? Core Java
Ans. Package is a namespace that organizes a set of related classes.
Advantages of Packages
1. Better Organization of classes.
2. Saves from the problem of duplicate names as duplicate class names are allowed across different packages. Help us improve. Please let us know the company, where you were asked this question : Like Discuss Correct / Improve  package  advantages of packages Asked in 1 Companies Basic Q1663. When String literals are compared using ==, they always returns true if the string values are same because .. Reference Core Java
a. of overridden compareTo method b. of overridden compare method c. of String Pool d. == means that the object contents are equalAns.c. of String Pool
Q1664. Which of the following is true ? Core Java
a. Composition is Tightly Bound b. Inheritance is Tightly Bound c. Object can only hold reference of only one other object d. A Class cannot be extended by multiple classesAns.b. Inheritance is Tightly Bound
a. x==y on all literals always returns false b. x.equals(y) on all literals always returns false c. if x.equals(y) returns true, x==y returns true too d. if x.equals(y) returns false, x==y returns trueAns.c. if x.equals(y) returns true, x==y returns true too
a. Constructor without parameters declared by user b. Constructor provided by Java if no constructor is declared c. Constructor with empty body d. All of the aboveAns.b. Constructor provided by Java if no constructor is declared
Q1667. How can we create objects if we make the constructor private ? Core Java
a. We can't create objects if constructor is private b. We can only create objects if we follow singleton pattern c. We can only create one object d. We can create new object through static method or static blockAns.d. We can create new object through static method or static block
Q1668. What will be the output of following ?
String str1 = new String("String1");
String str2 = new String("String1");
System.out.print(str1 == str2);
System.out.print(str1.equals(str2));
str1 = str2;
System.out.print(str1 == str2); Core Java
a. falsetruetrue b. truetruetrue c. truetruefalse d. falsetruefalseAns.a. falsetruetrue
Q1669. What will be the output of following code ?
String str1 = "String1";
String str2 = "String1";
System.out.print(str1 == str2);
System.out.print(str1.equals(str2));
str1 = str2;
System.out.print(str1 == str2); Core Java
a. falsetruetrue b. falsefalsetrue c. truetruetrue d. falsefalsefalseAns.c. truetruetrue
Q1670. What will be the output of following code ?
String str1 = "String1";
String str2 = "String2";
str1.concat("String3");
System.out.print(str1);
System.out.print(str2);
Core Java
a. String1String2 b. String1String3String3 c. String1String3String1String3 d. String1String1Ans.a. String1String2
Q1671. What will be the output of following code ?
String str1 = "String1";
String str2 = "String2";
str1=str1.concat("String3");
System.out.print(str1);
System.out.print(str2); Core Java
a. String1String2 b. String1String3String2 c. String1String2String3 d. String1Stringg3String1Ans.b. String1String3String2
Q1672. Which method needs to be implemented if a class is implementing comparable interface ? Core Java
a. comp b. compare c. compareTo d. compareEqualsAns.c. compareTo
Q1673. Which of the following is false ? Core Java
a. A Class cannot override both hashcode and equals method. b. A class can override both hashcode and equals method. c. A Class must override hashCode method if its overridding equal method. d. A Class can override hashCode even if its not overridding equals method.Ans.a. A Class cannot override both hashcode and equals method.
a. interface b. abstract class c. final class d. util classAns.d. util class
Q1675. Which of the following can throw ClassCastException ? Core Java
a. UpCasting b. DownCasting c. Casting to incompatible data type d. Casting to StringsAns.b. DownCasting
a. final instance methods b. final static methods c. non final instance methods d. non final static methodsAns.c. non final instance methods
Q1677. x instanceOf y returns false .. Core Java
a. if x is an instance of y class b. if x is an instance of class implementing y interface c. if x is an instance of class extending y class d. if x is an instance of Class which is a parent of Y classAns.d. if x is an instance of Class which is a parent of Y class
a. java.lang.Object b. java.lang.Thread c. java.lang.Runnable d. java.lang.ImplementAns.a. java.lang.Object
Q1679. if classes B and C extends Class A, Which of the following initialization is correct ? Core Java
a. B b = new C(); b. C c = new B(); c. B b = new A(); d. A a = new B();Ans.d. A a = new B();
Q1680. If X implements Y and Y extends Z, Which of the following initialization is correct ? Core Java
a. X x = new Y(); b. X x = new Z(); c. Z z = new Y(); d. Z z = new X();Ans.d. Z z = new X();