You are on page 1of 12

Java interview questions

Oops questions
1. What is oops?
-Oops stands for object oriented programming
-it is the programming lang technique to write program based on the real
word .
-it is the programming based on the concept of object. That contain data
and methods.
2. What are the concepts of oops
Object,class,abstaraction,encapsulation,inheritance,polymorphism.
3. What is object?
Object concept is termed as a specific instance of a class where the object
can be combined of data structure ,function and variables .its own state
behaviour and identity.
4. What is class?
A class is simply a representation of type of object or collection of object
are called class.
It is the blueprint from a plan or template that describe the details of an
object.
5. What is abstraction?
Data abstraction is the process of hiding certain details and showing only
essential info to the user.
6. Write a ex of abstraction class and method in java?
In class:
Abstraction class a {}
In method:
Abstract void printstatus();//
7. What is encapsulation?
Encapsulation is concept of wrapping code and data together into a single
unit.eg capsule which is mixed of several medicine
We can create fully encapsulated class in java by making all the data
members of the class is private.
Write a eg of encapsulation in java?
“Job” is encapsulated
Pub
8. What is polymorphism?
It means one name many different forms.
It is nothing but assigning behaviour or value in a subclass to something
that was alredy declared in the main class.
There are two types of polymorphism
Static : it is acchived using method overloading
Dynamic: it is using method overriding
9. Write eg of polymorphism in java?
10.What is inheritance?
Inheritance is a concept where one class shares the structure and
behaviour defined in another class.or is a mechanism in which one object
aquires all the properties and behaviour of a parent class.
If inheritance applied on one class is called single inheritance.
And if it is depends on multiple classes then it is called multiple inheritance.
11.What is the syntax of inheritance?
Class oopsconcept
{
Class java extends oopsconcept{
}
12.What is main diff between an object based programming lang and object
oriented programming lang?
Object oriented programming is to implement all concepts like
object,abstraction,inheritance,classes polymorphism etc.
Object based programming language follows all the concepts of oops
except inheritance such as javascript
13.What is association?
Association in java is a connection between two seprate classes that is set
up through their object.although it balance one to one one to many many
to many relationships.
14.What is composition?
15.What is aggregation?
Aggregation is also known as one way relationship between two objects it
represent “has a" relationship.
16.What is object cloning?
Object cloning refers to the creation of an exact copy of an object.
The clone() method of object class is used to clone an object.
17.What is manipulators?
Manipulators are the function which can be used in conjuction with the
insertion (<<) and extraction(>>) operators on an object eg endl.
18.What is constructor?*
A constructor in java is special method that is used to initialize objects. The
constructor is called when the object of the class is created. rules of the
constructor are
Name should be same as a class name ans conbstructor must have no
return tupe.
19.What is destructor?
It is the method which is automatically called when the object is made of
scope or destroyed. Destructor name is also same as a class name but with
the tidle symbol.
20.Can you define inline function?
No, there is no inline function in java you can use public static method
anywhere in code when placed in the public class. Java compiler may do
inline expansion on a static or final method.but not guaranteed.
21.Can you define virtual function?
Virtual function is a member function of a class .the parent class pointer is
used to refer to the object of the child class.the virtual function defined in
child class with same name as a parent class.
22. What is a abstract class?
An abstract class is class which can not be used to create object.to access it
it must be inherited from another class
-abstract method is an only use in abstract class and it does not have a
body.
23.What is interface?
An interface is a collection of abstract method.
If the class implements an inheritance, and then thereby inherits all the
abstract methods of an interface.

24.What is friend function?


Friend function is the friend of the class that is allowed to access to public,
private or protected data in the same class. If the function is defined
outside the class cannot access such information
Friend can be declared anywhere in the class declaration.
25. What is function overloading?
Function overloading is defined as a normal function. but it has the ability
to perform different tasks.
It allows creation of several methods with the same name which differ from
each other by type of input and output of the function.
Eg
Void add(int&a,int&b);
Void add(double&a,double&b);
26.Explain ternary operator?
Ternary operator is said to be an operator which takes three arguments.
Arguments and results are of different data types. And it is depending on
the function.
Ternary operator is also called as conditional operator.
27.What is operator overloading?
Operator is overloading is a functional where different operators are
applied and depends on the arguments. Operator -,* can be used to pass
through the function, and it has their own precedence to execute.
Eg op operation overloading
28.What is the finalize method?
Finalize method helps to perform clean-up operations on the resources
which are not currently used.
Finalize method is protected and it is accessible only through this class or
by derived class.
29.What are the different types of arguments?
A parameter is a variable during declaration of the function or subroutine
and arguments are passed to the function.and it should match with the
parameter defined.
2 types
Call by value:value passed will get modified only inside the function, and it
returns the same value whatever it is passed to the function
Call by reference: value pass will get modified in both inside and outside
the function and it returns same or different value.
30.Can you explain super keyword?
Super keyword is used to invoke overridden method in which overrides one
of its super class method this keyword allow to access overridden method
and also access hidden members of the super class.
31.Explain method overriding?
Method overriding is a feature that allows sub class to provide
implementation of method that is already defined in the main class
This will override the implementation in the super class by same method
same name and same parameter and same return type
32.What is exception handling?
Exception is a event that occurs during execution of the program
Exception can be of any type
Run time exception,error exception
Those exception are handled properly through exception handling
mechanism like try,catch and throw keywords.
33.Can you explain tokens?
Token is recognized by compiler and it cannot be broken down into
component element
34.What is the difference between overloading and overriding?
Overloading is static binding whereas overriding is dynamic binding.
Overloading is nothing but same method with different arguments., and it
may or may not return the same value in the same class itself
Overriding is the same method names with same argument and return type
associate with the class and its child class
35.What is the diff between class and object?
An object is an instance of the class
Object holds any information but classes don’t have any information.
Definition of properties and functions can be done at class and can be used
by the object.
Class can have sub claases and an object dosent have sub object
36.What is the diff between structure and class?
Structure default access type is public
Class access type is private
Structure is used for grouping data
Class can be used on grouping data an methods
37.Define abstraction?
Its feature of oops and it shows only the necessary details to the client of
an object means it shows only necessary details of the object. Nor the inner
details of an object.
38.*What are the access modifiers?
Access modifiers in java specifies the accessibility or scope of the field,
method constructor or class.----
5 type
Public,private,protected,friend,protected friend
39.How can we call the base method without creating an instance
Yes it is possible and the method should be static method
Doing inheritance from the class use base keyword from derived class.
40.What are the various types of constructor?
Default constructor-it is without no parameter
Parametric constructor
Copy constructor
41.What is this pointer?
This pointer refers to the current object of the class
It refers current object
42.What is the default access modifier in a class?
The default access modifier of a class is private by default
43.Why java does not support multiple inheritance?
Java is a simple programming lang and multiple introduce complexities such
as a diamond problem
44.What are the pros of oops programming
Simplicity,modularity,maintainability,reusability, effective problem solving

Core java questions


1. Why java consider dynamic?
Java is considered as dynamic because of bytecode
A source code written in one plaform the same code executed in any
platform
2. Define a class?
A class is template for objects
A class is user defiened blueprint from which objects are created
It represent set of properties or method that are common to all object.
3. What is a singleton class?
A singleton class control object creation. It allows only one instance of itself
to be created in other words it is a class that can have only one object.
4. What is static variable?
Static variable in java is variable which belongs to the class and initialized
only once at the start of the execution.it is the variable belongs to the class
not to object(instance)
5. What is the protected access modifier
It specifies that the member can only be accessed within its own package.
6. Why string called immutable?
String class consider immutable because one is created string object cannot
be changed.
** if u want modificn then in that case string buffer should be used
7. Explain imp of finalize method?
Finalize method called before garbage collector it is very handy it perform
cleanup activities and minimize memory leak.
8. Can we force garbage collector to run?
Yes we can force we can use runtime.gc(); for this purpose
9. What are the static method?
It is belong to the class rather than object there is no need to create object
call static method
10.What is the purpose of this keyword?
This keyword is refer to the current object
This can not be use in main method
11.Super keyword?
It refers a superclass (parent) object. It is used to call superclass methods
and to access the superclass constructor.
12.How objects are stored in java?
In java each object gets a memory space from a heap
When a object is destroyed by a garbage collector the space is allocate to
reallocate to heap made available for heap
13.What is polymorphism in java ?
What are the kinds of polymorphism?
*Polymorphism means many forms
And it occurs when we have many classes that are related to each other by
inheritance.
Polymorphishm use those method to perform different task.
2 types
Compile and run time
14.What is method overloading?
Method overloading allows us to create multiple methods with same name
but different signature
Method overloading in 2 way
Changing argument
Changing return type of method
15.Can main() method in java return any data?
Main method always declared void return type so it is not possible to
return any data
16.Can class have multiple constructor?
Yes, it have multiple constructor with different parameter
17.Is string a data type in java?
String is not primitive data type in java but it is a class a reference type
And it is object of
Java.lang.stringclass
18.What is multithreading?
It is a special from of multi tasking. Multiple task in concurrent manner
within a single program
19.Can use pointer in java?
No
20.Can class java be inherited more than one class?
Class can be derived only one class multiple inheritance not supported
21.What is garbage collector?
This is the process by which java program perform automatic memory
management through a garbage collector .
22.Can we have static method in an interface?
No
23.How does java reduce the chances of a program going out of memory?
Automatic garbage collection mechanism. That doesn’t ensure ki going out
of memory
24.Can we increase the size of an array after its declaration?
No array is static instead use vector over array.
25.What is the base class of all exception classes?
In java.lang.Throwable.
26.What is the order of call of constructor in inheritance?
It is call for multiple inheritance.

Javascript
1. What is javascript?
It is a client side scripting language.
Executes in the user browser
Enables to create interactive web pages. Js clap user initivtive event btnclick
displaying pop up msg valedating data etc.
Just text editor need to write code.
2. Diff betn java and javascript?
Java-object oriented programming lang file exetension.java can run on any
virtual browser or machine requires entire jdk to write a program
Javascript- object based scripting language, file extension .js runs on
browser require only text editor
3. What are the features of js?
It is lightweight object based scripting lang
It is case sensestive
It is a cross platform scripting lang
Can dynamically generate html content
4. What are scope of variable in js?
Two scope global and local
Global accessible from any where in code and local variable within a js
function
5. What is purpose
6. “this ” keyword in js?
It refers to the object from where it is called
7. *Difference between operator “==” vs “===”
== makes type correction, automatically convert one type into
another,return value based on content equality
=== support strict equality, return true only when both variable are of same
type and have same value
8. What is null in js?
It implies no value or no object
9. Diff between undeclared vs undefined variables?
Undeclared- no initialize or no declared
Throw runtime error
Undefined- declared but not assigning value
Returns undefined value.
10.How are innerhtml and inner text
Innerhtml-interprets html tag as html and set content in html format
Innertext. Interprets html tag as a text and set the tag content as a plain
text.
11.Event bubbling in js

Event first captured handled by target element and propagated to parent


elements until it reaches the document object.
Eg
<body onclick=”alert(‘body’)”>
<div onclick=”alert(‘div’)”>
<span onclick=”alert(‘span’)”> span</span>
</div>
</body>
12.What is nan js
Nan denotes not a number. We can use isNan()-function otherwise it false
13.Diff break vs continue statement?
Break-used to jump out of current loop without executing following
statement
Continue- skips remaining loop statements and continues with next
iteration in the loop.
14.Use of ‘type of operator’?
Returns string description of the operand
Eg type of”ashwini” // it returns “string”
Type of 20// it returns”number”
15.Different type of errors in js?
1. Syntax errors
Occu at interpret time
2. Run time errors
Occur during execution time
3. Logical errors
This occurs logic mistake
16.Role of strict mode in js
Sometimes js displays result even there are some errors
To overcome this problem we can use js scrit mode
Happen itn this mode the code throws all types of error
*to enable the strict mode write use strict at top of script
16. can you access cookies usin js?
Yes cookies can be read,created and erased by js acciceble to property
document.cookie
17.What is diff between null vs undefiened
Both is signified apsent of value
Null-null is special value represent no value when we assign null to variable
it signifies define the variable but not assigned value
Undefiened-variable declared but not defined yet
18.What is js data type?
Number Boolean ,string object undefeiend
19.what is promptbox?
It is a box that allows to user to enter input by providing text box
19.What are the pop boxes avelable in js?
Alert, conform and prompt.-
6

You might also like