JAVA interview question and answers on JAVA modifiers and data types

Below are the Java entry level interview questions and answers. These questions are about Java comments, Java Modifiers and Java Data Types. Read Interview questions and answers on JAVA platform, uses and important uses of JAVA.

1) What are Modifiers?
Modifiers are keywords that we add to those definitions to change their meaning.

2) What are the types of Modifiers in Java?
Two types of Modifiers in Java
  • Access Modifiers
  • Non Access Modifiers
3) What are Access Modifiers?
We use access modifiers to define access control for classes, methods and variables. Access Modifiers in Java are,
i) public
public access modifiers is accessible everywhere.
public class Sample{
ii) private
The private access modifier is accessible only within class.
private int a=100;
iii) default
If we don't specify any modifier then it is treated as default, this can be accessible only within package.
class Sample {
iv) protected
The protected modifier is accessible within package, outside of the package but through Inheritance.
protected class Sample {

4) What are the important Non Access Modifiers in Java?
i) static
static modifier is used to create classes, methods and variables.
ii) final
final modifier for finalizing classes, methods and variables.
iii) abstract
abstract modifier is used to create abstract classes and abstract methods. Etc...

5) What is Data type?
Data Type is a classification of the type of data that a variable or Constant or Method can hold in Computer program.
Ex: character, integer, float, boolean etc...
Java Supports Explicit declaration of data types.

6) What is Explicit declaration of data types?
We need to specify the data type before declaring variables or Constants.
Examples in Java:
int a;
int b=100;
int c, d, e;
int f=10, g=20, h=30;

7) What are the categories of Data Types in Java?
Two categories of Data Types in Java
  • Primitive Data Types
  • Non Primitive Data Types
8) What are Primitive Data Types in Java?
Primitive Data Types (8 Data types) in Java are,
i) Integer Data Types
a) byte (8 bits), Ex: byte a = 10;
b) short (16 bits), Ex: short b =10000;
c) int (32 bits), Ex: int c = 1000000;
d) long (64 bits), Ex: long d = 100000000000000000000;
ii) Relational data types (Numbers with decimal places)
e) float (32 bits), Ex: float x = 10.23;
f) double (64 bits), Ex: double y = 1245.34567897345;
iii) Characters
g) Character, Ex: char z = "A";
iv) Conditional
h) Boolean, Ex: boolean x = true/false;

9) What are Non Primitive Data Types?
Non Primitive Data Types Or Reference data Types in Java are Objects and Arrays.
Sample obj = new Sample();

10) What are Comments in Computer Program?
Comments are English words used for Code documentation. Purpose of Comments
  •  To make the code Readable
  • To make the code disable from Execution
11) How to write comments in Java?
Java supports Single line comment and multiple line comment.
a) Use // for Single line comment
b) Use /*..........
-------------*/ for multiple line comment
In Eclipse IDE,
Select Statements/Steps
Source menu -> Add Block Comment
Select Comment block
Source menu -> Remove Block Comment

0 Comment to "JAVA interview question and answers on JAVA modifiers and data types "

Post a Comment