Interview Questions and Answers - Order By Newest Q1471. Is this array declaration correct ? If not , Why ?
String[] strArray = new String[]; Core Java
Ans. No, We haven't specified the size of array to be initialized. Help us improve. Please let us know the company, where you were asked this question : Like Discuss Correct / Improve  arrays  array initialization Q1472. Is this array initialization correct ? If Yes, What will be the size of array ?
String[] strArray = new String[]{"Buggy","Bread"}; Core Java
Ans. Yes, size of the array will be 2. Help us improve. Please let us know the company, where you were asked this question : Like Discuss Correct / Improve  arrays  array initialization Q1473. Is this array initialization correct ? If Yes, What will be the size of array ?
String[] strArray = new String[3]{"Buggy","Bread"}; Core Java
Ans. No. It will result in error saying "Cannot define dimension expressions when an array initializer is provided" Help us improve. Please let us know the company, where you were asked this question : Like Discuss Correct / Improve  arrays  array initialization Q1474. Is this code valid
String[] strArray = new String[2];
strArray.length = 5; Core Java
Ans. It will give compile time error saying "The final field array.length cannot be assigned"
Arrays once initialized cannot be resized. Help us improve. Please let us know the company, where you were asked this question : Like Discuss Correct / Improve  arrays  array initialization Q1475. What is the problem with this code
String[] strArray = new String[2];
strArray[0] = 5; Core Java
Ans. We are trying to add an integer element to an array of String. Will give compile time error. Help us improve. Please let us know the company, where you were asked this question : Like Discuss Correct / Improve  arrays Q1476. Will this give compile time error ?
Object[] strArray = new String[2];
strArray[0] = 5; Core Java
Ans. No. But It will throw ArrayStoreException at runtime. Help us improve. Please let us know the company, where you were asked this question : Like Discuss Correct / Improve  ArrayStoreException  arraysAns. Assigning a value of one type to a variable of another type is known as Type Casting.
Example :
int x = 10;
byte y = (byte)x;
In Java, type casting is classified into two types, Widening Casting(Implicit) widening-type-conversion and Narrowing Casting (Explicitly done) narrowing-type-conversion.
Widening or Automatic type converion - Automatic Type casting take place when,the two types are compatible and the target type is larger than the source type
Example :
public class Test {
public static void main(String[] args) {
int i = 100;
long l = i; //no explicit type casting required
float f = l;//no explicit type casting required
System.out.println("Int value " i);
System.out.println("Long value " l);
System.out.println("Float value " f);
}
}
Narrowing or Explicit type conversion - When you are assigning a larger type value to a variable of smaller type, then you need to perform explicit type casting.
Example :
public class Test{
public static void main(String[] args) {
double d = 100.04;
long l = (long)d; //explicit type casting required
int i = (int)l;//explicit type casting required
System.out.println("Double value " d);
System.out.println("Long value " l);
System.out.println("Int value " i);
}
} Help us improve. Please let us know the company, where you were asked this question : Like Discuss Correct / Improve  typecasting  type casting Asked in 23 Companies Q1478. What is the biggest Design problem 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   Q1479. Write a java program to find the maximum profit in day trading Core Java
This question was recently asked at 'Capital One'.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   Asked in 1 Companies Q1480. What are basic functions of OOPS ? Core Java
This question was recently asked at 'Zillious'.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   Asked in 1 Companies Q1481. Where to use interface and abstract class ? Core Java
This question was recently asked at 'Exterro,Equator Business Solutions'.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   Asked in 2 Companies Q1482. Does Java SE has Immutable collections ? Core Java
Ans. Yes wef from Java 9 Help us improve. Please let us know the company, where you were asked this question : Like Discuss Correct / Improve  java 9  java9  immutable  immutability collections Q1483. Can you write immutable class without final? Core Java
Ans. By making the constructor private Help us improve. Please let us know the company, where you were asked this question : Like Discuss Correct / Improve   Asked in 1 Companies Q1484. Is java fully platform independent ? Core Java
Ans. yes, Java is a class-based and object-oriented programming language. It is a platform-independent language i.e. the compiled code can be run on any java supporting platform. It runs on the logic of “Write once, run anywhere”. Help us improve. Please let us know the company, where you were asked this question : Like Discuss Correct / Improve   Asked in 1 Companies Q1485. Can we use try within catch block ? Core Java
Ans. Yes Help us improve. Please let us know the company, where you were asked this question : Like Discuss Correct / Improve   Asked in 1 Companies Q1486. Isnt the use of HashTable and ConcurrentHashMap the same, i.e providing synchronized map collection ? Core Java
Ans. Both provide the thread safety but the actual difference come when talk about performance. CHM gives best performance when no of writer threads are less in number. Help us improve. Please let us know the company, where you were asked this question : Like Discuss Correct / Improve  synchronized collections  hashtable  ConcurrentHashMap Asked in 1 Companies Q1487. Will it print the message in Base Class constructor if we execute main method of Main class ? why ?
public class BaseClass {
BaseClass(){
System.out.println("Hello I am in Base Class Constructor");
}
}
public class DerivedClass extends BaseClass{
}
public class Main {
public static void main(String[] args) {
DerivedClass derivedClass = new DerivedClass();
}
} Core Java
Ans. Yes.
When the Derived class constructor is initialized , a no argument super will be called intrinsically. Help us improve. Please let us know the company, where you were asked this question : Like Discuss Correct / Improve  constructor Q1488. What will the following print upon executing main method of Main class ?
public class BaseClass {
BaseClass(){
System.out.println("Hello I am in Base Class Constructor");
}
}
public class DerivedClass extends BaseClass{
DerivedClass(){
System.out.println("Hello I am in Derived Class Constructor");
}
}
public class Main {
public static void main(String[] args) {
DerivedClass derivedClass = new DerivedClass();
}
} Core Java
Ans. Hello I am in Base Class Constructor
Hello I am in Derived Class Constructor Help us improve. Please let us know the company, where you were asked this question : Like Discuss Correct / Improve  constructor Q1489. What will the following code print upon executing main method of Main class ?
public class BaseClass {
BaseClass(){
System.out.println("Hello I am in Base Class Constructor");
}
}
public class DerivedClass extends BaseClass{
DerivedClass(){
System.out.println("Hello I am in Derived Class Constructor");
super();
}
}
public class Main {
public static void main(String[] args) {
DerivedClass derivedClass = new DerivedClass();
}
}
Core Java
Ans. There will be compilation error within constructor of Derived Class as "super must be the first statement in constructor body". Help us improve. Please let us know the company, where you were asked this question : Like Discuss Correct / Improve  constructor Q1490. What will the following code print upon executing main method of Main class ?
public class BaseClass {
BaseClass(int x){
System.out.println("Hello I am in Base Class Constructor");
}
}
public class DerivedClass extends BaseClass{
DerivedClass(){
System.out.println("Hello I am in Derived Class Constructor");
}
}
public class Main {
public static void main(String[] args) {
DerivedClass derivedClass = new DerivedClass();
}
} Core Java
Ans. Compilation error as there is no default constructor available in BaseClass. Help us improve. Please let us know the company, where you were asked this question : Like Discuss Correct / Improve  constructor Q1491. What will the following code print upon executing main method of Main class ?
public class BaseClass {
BaseClass(int x){
System.out.println("Hello I am in Base Class Constructor");
}
}
public class DerivedClass extends BaseClass{
DerivedClass(){
super(1);
System.out.println("Hello I am in Derived Class Constructor");
}
}
public class Main {
public static void main(String[] args) {
DerivedClass derivedClass = new DerivedClass();
}
} Core Java
Ans. Hello I am in Base Class Constructor
Hello I am in Derived Class Constructor Help us improve. Please let us know the company, where you were asked this question : Like Discuss Correct / Improve  constructor Q1492. Why line 4 in this code gives error saying "Cannot be referenced from a static context" ?
public class OuterClass {
public static void main(String[] args){
InnerClass innerClass = new InnerClass();
}
class InnerClass {
}
} Core Java
Ans. InnerClass is a non static inner class and hence can only be instantiated using instance of the outer class. Help us improve. Please let us know the company, where you were asked this question : Like Discuss Correct / Improve  inner class Q1493. What will the following code print upon executing main method of Main class
public class BaseClass {
BaseClass(){
this(2);
System.out.println("Hello I am in Base Class Constructor");
}
BaseClass(int i){
System.out.println("Hello I am in Base Class int argument Constructor");
}
}
public class DerivedClass extends BaseClass{
DerivedClass(){
super(1);
System.out.println("Hello I am in Derived Class Constructor");
}
}
public class Main {
public static void main(String[] args) {
DerivedClass derivedClass = new DerivedClass();
}
} Core Java
Ans. Hello I am in Base Class int argument Constructor
Hello I am in Base Class Constructor
Hello I am in Derived Class Constructor Help us improve. Please let us know the company, where you were asked this question : Like Discuss Correct / Improve  constructor Q1494. What will the following code print upon executing main method of Main class
public class BaseClass {
BaseClass(){
this(2);
System.out.println("Hello I am in Base Class Constructor");
}
BaseClass(int i){
System.out.println("Hello I am in Base Class int argument Constructor");
}
}
public class DerivedClass extends BaseClass{
DerivedClass(){
System.out.println("Hello I am in Derived Class Constructor");
}
}
public class Main {
public static void main(String[] args) {
DerivedClass derivedClass = new DerivedClass();
}
} Core Java
Ans. Hello I am in Base Class int argument Constructor
Hello I am in Base Class Constructor
Hello I am in Derived Class Constructor Help us improve. Please let us know the company, where you were asked this question : Like Discuss Correct / Improve  constructor Q1495. Why string pool concept has been introduced in string ? Core Java
Ans. Memory Sharing and Optimal memory utilization. Help us improve. Please let us know the company, where you were asked this question : Like Discuss Correct / Improve  String Pool Asked in 1 Companies Q1496. How can we check class file format in java ? Core Java
This question was recently asked at 'Jagan Institute of Management Studies (JIMS)'.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   Asked in 1 Companies Q1497. What is the use of final String when Strings are immutable ? Core Java
This question was recently asked at 'Cyient'.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  string Asked in 1 Companies Q1498. What is type script ? What are the advantages of typescript ? How is it different than javascript ? TypeScript
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  Typescript vs Javascript This question was recently asked at 'Amber Road'.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   Asked in 1 Companies Q1500. Does Hashtable in Java use stack operation ? 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