BASIC CORE JAVA INTERVIEW QUESTIONS AND ANSWERS
CORE JAVA
1. WHAT IS JAVA:-
A programming language created in 1995 by James Gosling, now owned by Oracle, is secure, fast, and powerful. It supports multi-paradigm development, and it has huge community support. It is used to develop mobile applications, desktop applications, Web applications, Web servers, Games, and Database connections. It runs on more than 3 billion devices.
2. HOW IS A JAVA PROGRAM EXECUTED:-
source code => Compiler => bytecode(.class file) => JVM => Machine code (010100..)
3. HOW IS JAVA PLATFORM INDEPENDENT:-
source code => compiler(Java code cane be written once and run anywhere) => bytecode(.class file) this is platform independent
4. WHAT ARE THE VARIOUS ACCESS SPECIFIERS IN JAVA:-
Access Specifiers define the scope or accessibility
1. Public
2. Private
3. Protected
4. Default
1. Public:- The Data items and functions are accessible from anywhere.
2. Private:- Accessible from the class where they are defined
3. Protected:- Accessible from the class, package, subclass, and within the class.
4. Default:- Accessible from all classes.
5. WHAT IS A METHOD IN JAVA:-
A Method is a block of code. Also called as function can also take input of data in the form of parameters must be declared within a class.
public int sum(){}
System.out.println()
public class Main(){
static void methodName(){
//method body
}
}
6. WHAT IS THE JAVA MAIN() METHOD:-
Entry point of a Java program
class Main(){
public static void main(String[] args){
//method body
}
}
7. WHAT IS (String[] args) THAT ALWAYS APPEARED ON THE JAVA main() METHOD:-
String[] is used to declare a simple string array. args is the name of a string array. args stores the command line arguments.
8. WHAT IS A STATIC METHOD:-
Accessed directly by specifying its name called without creating an object of the class. A static method belongs to the class and doesn't require any object state.
9. WHAT IS METHOD OVERLOADING:-
Multiple methods can have the same name with different parameters. by changing the number of arguments and by changing the data type of the arguments.
static int myMethod(int x, int y)
static double myMethod(double x, double y)
10. CAN WE OVERLOAD THE main() METHOD:-
Yes, we can overload the main method. The compiler will check for the parameters (String[] args) in the main method and will recognize it as the entry point into the program.
JVM always calls the original main() method. It does not call the overloaded main()method.
11. WHAT IS A CONSTRUCTOR IN JAVA:-
used to initialize objects. must have the same name as that of the class. does not have a return type. Every time an object is created using the new keyword, the default constructor is called.
12. HOW MANY TYPES OF CONSTRUCTORS ARE USED IN JAVA:-
1. No argument Constructor
2. Parametrized Constructor
3. Default Constructor
13. WHAT IS INHERITANCE IN JAVA:-
Inheritance is the process by which a class acquires the attributes and methods of another class. This promotes code reusability.
example Animal:- cat,dog
14. WHAT ARE SUBCLASS AND SUPERCLASS:-
Subclass is the class that inherits from another class
Superclass is the class that is being inherited from, like
example: Vehicle:- bus, car, truck is a subclass and vehicle is a super class
Comments
Post a Comment