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. |
|
| ||||
Core Java - Interview Questions and Answers for 'Default' - 40 question(s) found - Order By Rating | ||||
| ||||
Ans. Default VPC is provided by AWS whereas custom VPC needs to be created. All subnets in default VPC have internet access whereas it's specified by user in Custom VPC. | ||||
Help us improve. Please let us know the company, where you were asked this question : | ||||
Like Discuss Correct / Improve  aws vpc   aws default vs custom vpc | ||||
| ||||
Ans. Default size is 10. Regard how size will increase. Inside add() method there is one method called ensureCapacity() which will check list has enough size available. This ensureCapacity() method if found size of list need to increase then it will call grow() method which will create new list of extra size and copy existing list data to new one and return. | ||||
Help us improve. Please let us know the company, where you were asked this question : | ||||
Like Discuss Correct / Improve  list  default size of list Asked in 1 Companies | ||||
| ||||
Ans. Java 1.8 or Java 8 | ||||
Help us improve. Please let us know the company, where you were asked this question : | ||||
Like Discuss Correct / Improve  default methods   interface default methods   java 8  java 8 features | ||||
| ||||
Ans. No. The whole idea of default method is to provide a default definition in case the implementing class intend to provide definition for only some of the methods. Making any of the interface method private would restrict it from being implemented by the implementing class. So default method is an option to provide implementation and not restricting a new definition. | ||||
Help us improve. Please let us know the company, where you were asked this question : | ||||
Like Discuss Correct / Improve  java 9  default methods | ||||
| ||||
Ans. Java 8 allowed for method implementation using default methods in interfaces. As those default methods could contain complex logic and might need organizing the logic into multiple methods, they have allowed for private methods. | ||||
Help us improve. Please let us know the company, where you were asked this question : | ||||
Like Discuss Correct / Improve  java 9  default methods | ||||
| ||||
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 | ||||
| ||||
Ans. Interfaces don't have member elements and method definitions that could cause diamond problem. With Java 8, Interfaces have default method definitions. This could have created diamond problem but Java introduced a compile time check for "duplicate default methods" in case same method is derived from multiple interfaces and no definition is overridden by the class. | ||||
Help us improve. Please let us know the company, where you were asked this question : | ||||
Like Discuss Correct / Improve  diamond problem  interfaces  java 8  default methods | ||||
| ||||
Ans. It will print the garbage value as compiler doesn't provide a default value to local variables. | ||||
Help us improve. Please let us know the company, where you were asked this question : | ||||
Like Discuss Correct / Improve  local variable  default values basic | ||||
| ||||
Ans. Java provides a default constructor ( no argument ) if no constructor is provided by the programmer. Java makes a check during pre compilation if there is any constructor provided by the programmer. If any constructor is provided, Java understands that programmer has provided all the mechanism for initialization and construction of the object and may not even intend to create objects by calling a no argument constructor. For example - One may like to have objects created with self defined state otherwise restrict its creation. We make the constructor private if we want to make a class singleton as we would like to restrict creation of new objects using new operator and default constructor. Similar could be the situation wherein we would like to construct objects in a particular manner only. | ||||
Help us improve. Please let us know the company, where you were asked this question : | ||||
Like Discuss Correct / Improve  default constructor expert | ||||
| ||||
Ans. It gets the default access i.e package protected. | ||||
Help us improve. Please let us know the company, where you were asked this question : | ||||
Like Discuss Correct / Improve  access specifiers  default Access specifier Basic | ||||
| ||||
Ans. No. Default constructor is provided by compiler if no constructor is provided ( argument or no argument ) by us. | ||||
Help us improve. Please let us know the company, where you were asked this question : | ||||
Like Discuss Correct / Improve  constructor  default constructor Asked in 1 Companies | ||||
Try 1 Question(s) Test | ||||
| ||||
Ans. https://www.redhat.com/archives/rhl-list/2005-April/msg04167.html | ||||
Help us improve. Please let us know the company, where you were asked this question : | ||||
Like Discuss Correct / Improve  unix  change default kernel Asked in 1 Companies | ||||
| ||||
Ans. Default methods results in multiple inheritance of behavior and not of state. In case we try to implement multiple interfaces with default method having same name and signature, and don't override it in implementation class, it will throw an error. For example - interface MyInterface { public void default myMethod(){ } } interface MyInterface2 { public void default myMethod(){ } } class MyClass implements MyInterface,MyInterface2 { } This code will compilation error "Duplicate Default Method" if we specify the definition of myMethod() in myClass, compiler won't complain and there is no conflict and MyClass can use overridden definition. But if we don't override myMethod() in MyClass, Java would be in conflict as to what definition should be carried to MyClass and hence throws compilation error. | ||||
Help us improve. Please let us know the company, where you were asked this question : | ||||
Like Discuss Correct / Improve  default methods  java 8  multiple inheritance  object oriented programming (oops)  oops concepts  diamond problem   interfaces | ||||
| ||||
Ans. Earlier any class implementing an interface was supposed to implement all methods declared in an interface. There was no place for optionally implementing all or subset of methods.Though we have abstract classes wherein we could have provided such a mechanism by declaring some methods as abstract while providing definition for some. But as Abstract classes have a body and are comparatively heavier than interfaces and interfaces associate closely to the concept of providing interfacing than abstract classes, Java might have though of providing optional implementation for default methods. This way same interface can be reused in variety of ways rather than making copies of an interface to suit different needs. | ||||
Help us improve. Please let us know the company, where you were asked this question : | ||||
Like Discuss Correct / Improve  java 8   java8  interface default methods  default methods Asked in 6 Companies | ||||
Very Frequently asked across all type of companies and across all levels. | ||||
| ||||
Ans. Private - Not accessible outside object scope. Public - Accessible from anywhere. Default - Accessible from anywhere within same package. Protected - Accessible from object and the sub class objects. | ||||
Help us improve. Please let us know the company, where you were asked this question : | ||||
Like Discuss Correct / Improve  java   oop   access specifier   public   private   default   protected   public vs private vs default vs protected Asked in 12 Companies basic   frequent | ||||
Try 1 Question(s) Test | ||||
| ||||
Ans. boolean ---> false byte ----> 0 short ----> 0 int -----> 0 long ------> 0l char -----> /u0000 float ------> 0.0f double ----> 0.0d any object reference ----> null | ||||
Help us improve. Please let us know the company, where you were asked this question : | ||||
Like Discuss Correct / Improve  java   data types   default values | ||||
Try 1 Question(s) Test | ||||
| ||||
Ans. member variable are loaded into heap, so they are initialized with default values when an instance of a class is created. In case of local variables, they are stored in stack until they are being used. | ||||
Help us improve. Please let us know the company, where you were asked this question : | ||||
Like Discuss Correct / Improve  java   jvm   memory management   variables   stack memory   heap memory   default values expert | ||||
Recently asked in Infoview Technologies. | ||||
| ||||
Ans. The no argument constructor provided by Java Compiler if no constructor is specified. | ||||
Help us improve. Please let us know the company, where you were asked this question : | ||||
Like Discuss Correct / Improve  java   oops   constructor   default constructor Asked in 1 Companies Basic   frequent | ||||
Try 2 Question(s) Test | ||||
| ||||
Ans. No, Compiler will create default constructor only if we don't specify any constructor. | ||||
Help us improve. Please let us know the company, where you were asked this question : | ||||
Like Discuss Correct / Improve  java   oops   constructor   default constructor   yes-no expert   rare | ||||
Try 1 Question(s) Test | ||||
| ||||
Ans. Class.getInstance doesn't call the constructor whereas if we create an object using new operator , we need to have a matching constructor or copiler should provide a default constructor. | ||||
Help us improve. Please let us know the company, where you were asked this question : | ||||
Like Discuss Correct / Improve  java   constructor   object creation   default constructor   getinstance   new operator | ||||
| ||||
Ans. Yes , using Class.getInstance. | ||||
Help us improve. Please let us know the company, where you were asked this question : | ||||
Like Discuss Correct / Improve  java   oops   constructor   default constructor   class.getinstance | ||||
| ||||
Ans. No. Every Class only needs to have one constructor - With parameters or without parameters. Compiler provides a default non parameterized constructor if no constructors is defined. | ||||
Help us improve. Please let us know the company, where you were asked this question : | ||||
Like Discuss Correct / Improve  java   oops   constructor   default constructor   yes no intermediate | ||||
Try 3 Question(s) Test | ||||
| ||||
Ans. The default value of the boolean type is false. | ||||
Help us improve. Please let us know the company, where you were asked this question : | ||||
Like Discuss Correct / Improve  java   data type   boolean   initialization   default object construction   default constructor   default value | ||||
| ||||
Ans. At the beginning of an object's life, the Java virtual machine (JVM) allocates memory on the heap to accommodate the object's instance variables. When that memory is first allocated, however, the data it contains is unpredictable. If the memory were used as is, the behavior of the object would also be unpredictable. To guard against such a scenario, Java makes certain that memory is initialized, at least to predictable default values before it is used by any code. | ||||
Help us improve. Please let us know the company, where you were asked this question : | ||||
Like Discuss Correct / Improve  java   constructor   oops   default constructor   jvm expert | ||||
Try 2 Question(s) Test | ||||
| ||||
Ans. Java expects the superclass ( Object Class ) constructor to be called while creation of any object. So super constructor is called in case there are no instance variables to initialize. | ||||
Help us improve. Please let us know the company, where you were asked this question : | ||||
Like Discuss Correct / Improve  java   constructor   object creation   default constructor   super | ||||
Try 1 Question(s) Test | ||||
Ans. The code will not compile raising an error that the local variable y might not have been initialized. Unlike member variables, local variables are not automatically initialized to the default values for their declared type. | ||||
Help us improve. Please let us know the company, where you were asked this question : | ||||
Like Discuss Correct / Improve  java   code   default value | ||||
| ||||
Ans. Compile time error as it won't find the constructor matching BuggyBread2(). Compiler won't provide default no argument constructor as programmer has already defined one constructor. Compiler will treat user defined BuggyBread2() as a method, as return type ( void ) has been specified for that. | ||||
Help us improve. Please let us know the company, where you were asked this question : | ||||
Like Discuss Correct / Improve  java   code   coding   tricky questions   interesting questions   default constructor   constructor | ||||
Try 3 Question(s) Test | ||||
| ||||
Ans. Base Class Definition. | ||||
Help us improve. Please let us know the company, where you were asked this question : | ||||
Like Discuss Correct / Improve  java   java8   default methods | ||||
Rarely asked as default methods have been introduced with Java 8. | ||||
| ||||
Ans. No. Compiler will give error. | ||||
Help us improve. Please let us know the company, where you were asked this question : | ||||
Like Discuss Correct / Improve  java   java8   default method   yes-no   rare | ||||
| ||||
Ans. No. Compilation error. | ||||
Help us improve. Please let us know the company, where you were asked this question : | ||||
Like Discuss Correct / Improve  java   java8   default method   yes-no Asked in 1 Companies intermediate | ||||