What are the various access specifiers in Java? In Java, access specifiers are the keywords which are used to define the access scope of the method, class, or a variable. In Java, there are four access specifiers given below.
Public The classes, methods, or variables which are defined as public, can be accessed by any class or method.
Protected Protected can be accessed by the class of the same package, or by the sub-class of this class, or within the same class.
Default Default are accessible within the package only. By default, all the classes, methods, and variables are of default scope.
Private The private class, methods, or variables defined as private can be accessed within the class only. For More Questions Visit :- πππππ https://cjavapoint.blogspot.com/
Public The classes, methods, or variables which are defined as public, can be accessed by any class or method.
Protected Protected can be accessed by the class of the same package, or by the sub-class of this class, or within the same class.
Default Default are accessible within the package only. By default, all the classes, methods, and variables are of default scope.
Private The private class, methods, or variables defined as private can be accessed within the class only. For More Questions Visit :- πππππ https://cjavapoint.blogspot.com/
Check out this post⦠"Composition in Java Example - Learn Java".
http://cjavapoint.blogspot.com/2019/12/composition.html
http://cjavapoint.blogspot.com/2019/12/composition.html
Check out this post⦠"What is data hiding in a program? - Learn Java".
http://cjavapoint.blogspot.com/2019/09/data-hiding.html
http://cjavapoint.blogspot.com/2019/09/data-hiding.html
Core java Interview Questions for All. Aggregation
Learn java interview questions for student.learn java,core java interview question,java interview question.
Without existing container object if there is a chance of existing contained objects
such type of relationship is called aggregation .
in aggregation objects have weak association.
Example:
Within a department there may be a chance of several professors will work whenever
we are closing department still there may be a chance of existing department object the
relationship between department and professor is called aggregation where the objects
having weak association.
More Questions Visit My Blog ππππππππhttps://cjavapoint.blogspot.com/
Learn java interview questions for student.learn java,core java interview question,java interview question.
Without existing container object if there is a chance of existing contained objects
such type of relationship is called aggregation .
in aggregation objects have weak association.
Example:
Within a department there may be a chance of several professors will work whenever
we are closing department still there may be a chance of existing department object the
relationship between department and professor is called aggregation where the objects
having weak association.
More Questions Visit My Blog ππππππππhttps://cjavapoint.blogspot.com/
Exception handling Interview Questions
Q) What is an exception?
Exceptions are abnormal conditions that arise during execution of the program. It may occur due to wrong user input or wrong logic written by programmer.
Q) Exceptions are defined in which java package? OR which package has definitions for all the exception classes?
Java.lang.Exception
This package contains definitions for Exceptions.
https://cjavapoint.blogspot.com/
Q) What is an exception?
Exceptions are abnormal conditions that arise during execution of the program. It may occur due to wrong user input or wrong logic written by programmer.
Q) Exceptions are defined in which java package? OR which package has definitions for all the exception classes?
Java.lang.Exception
This package contains definitions for Exceptions.
https://cjavapoint.blogspot.com/
Q) What is throw keyword in exception handling?
The throw keyword is used for throwing user defined or pre-defined exception.
Q) What is throws keyword?
If a method does not handle a checked exception, the method must declare it using the throwskeyword. The throws keyword appears at the end of a methodβs signature.
https://cjavapoint.blogspot.com/
The throw keyword is used for throwing user defined or pre-defined exception.
Q) What is throws keyword?
If a method does not handle a checked exception, the method must declare it using the throwskeyword. The throws keyword appears at the end of a methodβs signature.
https://cjavapoint.blogspot.com/
Q1) What is the difference between an Inner Class and a Sub-Class?
Ans: An Inner class is a class which is nested within another class. An Inner class has access rights for the class which is nesting it and it can access all variables and methods defined in the outer class.
A sub-class is a class which inherits from another class called super class. Sub-class can access all public and protected methods and fields of its super class
https://cjavapoint.blogspot.com/
Ans: An Inner class is a class which is nested within another class. An Inner class has access rights for the class which is nesting it and it can access all variables and methods defined in the outer class.
A sub-class is a class which inherits from another class called super class. Sub-class can access all public and protected methods and fields of its super class
https://cjavapoint.blogspot.com/
Q2) What are the various access specifiers for Java classes?
Ans: In Java, access specifiers are the keywords used before a class name which defines the access scope. The types of access specifiers for classes are:
1) Public: Class,Method,Field is accessible from anywhere.
2) Protected: Method,Field can be accessed from the same class to which they belong or from the sub-classes, and from the class of same package, but not from outside.
3) Default: Method,Field,class can be accessed only from the same package and not from outside of itβs native package.
4) Private: Method,Field can be accessed from the same class to which they belong.
https://cjavapoint.blogspot.com/
Ans: In Java, access specifiers are the keywords used before a class name which defines the access scope. The types of access specifiers for classes are:
1) Public: Class,Method,Field is accessible from anywhere.
2) Protected: Method,Field can be accessed from the same class to which they belong or from the sub-classes, and from the class of same package, but not from outside.
3) Default: Method,Field,class can be accessed only from the same package and not from outside of itβs native package.
4) Private: Method,Field can be accessed from the same class to which they belong.
https://cjavapoint.blogspot.com/
Q3) Whatβs the purpose of Static methods and static variables?
Ans: When there is a requirement to share a method or a variable between multiple objects of a class instead of creating separate copies for each object, we use static keyword to make a method or variable shared for all objects
https://cjavapoint.blogspot.com/
Ans: When there is a requirement to share a method or a variable between multiple objects of a class instead of creating separate copies for each object, we use static keyword to make a method or variable shared for all objects
https://cjavapoint.blogspot.com/
Q4) What is data encapsulation and whatβs its significance?
Ans: Encapsulation is a concept in Object Oriented Programming for combining properties and methods in a single unit.
Encapsulation helps programmers to follow a modular approach for software development as each object has its own set of methods and variables and serves its functions independent of other objects. Encapsulation also serves data hiding purpose.
https://cjavapoint.blogspot.com/
Ans: Encapsulation is a concept in Object Oriented Programming for combining properties and methods in a single unit.
Encapsulation helps programmers to follow a modular approach for software development as each object has its own set of methods and variables and serves its functions independent of other objects. Encapsulation also serves data hiding purpose.
https://cjavapoint.blogspot.com/
Q5) What is a singleton class? Give a practical example of its usage.
A singleton class in java can have only one instance and hence all its methods and variables belong to just one instance. Singleton class concept is useful for the situations when there is a need to limit the number of objects for a class.
The best example of singleton usage scenario is when there is a limit of having only one connection to a database due to some driver limitations or because of any licensing issues.
https://cjavapoint.blogspot.com/
A singleton class in java can have only one instance and hence all its methods and variables belong to just one instance. Singleton class concept is useful for the situations when there is a need to limit the number of objects for a class.
The best example of singleton usage scenario is when there is a limit of having only one connection to a database due to some driver limitations or because of any licensing issues.
https://cjavapoint.blogspot.com/
Q7: What is an infinite Loop? How infinite loop is declared?
Ans: An infinite loop runs without any condition and runs infinitely. An infinite loop can be broken by defining any breaking logic in the body of the statement blocks.
Infinite loop is declared as follows:
for (;;) {
// Statements to execute //
Add any loop breaking logic
}
https://cjavapoint.blogspot.com/
Ans: An infinite loop runs without any condition and runs infinitely. An infinite loop can be broken by defining any breaking logic in the body of the statement blocks.
Infinite loop is declared as follows:
for (;;) {
// Statements to execute //
Add any loop breaking logic
}
https://cjavapoint.blogspot.com/
What is the difference between double and float variables in Java?
Ans: In java, float takes 4 bytes in memory while Double takes 8 bytes in memory. Float is single precision floating point decimal number while Double is double precision decimal number.
https://cjavapoint.blogspot.com/
Ans: In java, float takes 4 bytes in memory while Double takes 8 bytes in memory. Float is single precision floating point decimal number while Double is double precision decimal number.
https://cjavapoint.blogspot.com/
Is Empty .java file name a valid source file name?
Yes, Java allows to save our java file by .java only, we need to compile it by javac .java and run by java classname Let's take a simple example:
//save by .java only
class A{
public static void main(String args[]){
System.out.println("Hello java");
}
}
//compile by javac .java
//run by java A
compile it by javac .java
run it by java A
https://cjavapoint.blogspot.com/2019/12/method-signature.html?m=1
Yes, Java allows to save our java file by .java only, we need to compile it by javac .java and run by java classname Let's take a simple example:
//save by .java only
class A{
public static void main(String args[]){
System.out.println("Hello java");
}
}
//compile by javac .java
//run by java A
compile it by javac .java
run it by java A
https://cjavapoint.blogspot.com/2019/12/method-signature.html?m=1
Blogspot
What is a method signature in Java? -Learn Java
online java learn interview questions.full core java interview questions on java learn.
In java, method signature consists of name of the method followed by argument types.
core java interview questions.
What is a method signature in Java? -Learn Java
In java, method signature consists of name of the method followed by argument types.
core java interview questions.
What is a method signature in Java? -Learn Java
class FibonacciExample2
{
static int n1=0,n2=1,n3=0;
static void printFibonacci(int count)
{
if(count>0)
{
n3 = n1 + n2;
n1 = n2;
n2 = n3;
System.out.print(" "+n3);
printFibonacci(count-1);
}
}
public static void main(String args[])
{
int count=10;
System.out.print(n1+" "+n2);
//printing 0 and 1
printFibonacci(count-2);
//n-2 because 2 numbers are already printed
}
}
https://cjavapoint.blogspot.com/?m=1
{
static int n1=0,n2=1,n3=0;
static void printFibonacci(int count)
{
if(count>0)
{
n3 = n1 + n2;
n1 = n2;
n2 = n3;
System.out.print(" "+n3);
printFibonacci(count-1);
}
}
public static void main(String args[])
{
int count=10;
System.out.print(n1+" "+n2);
//printing 0 and 1
printFibonacci(count-2);
//n-2 because 2 numbers are already printed
}
}
https://cjavapoint.blogspot.com/?m=1
Blogspot
Core Java Interview Questions - Learn Java
Java Tutorial or Learn Java or Core Java Tutorial or Java Programming Tutorials for beginners and professionals with core concepts and examples
π1
import java.util.Scanner;
public class FibonaciiSeries
{
public static void main(String[] args)
{
Scanner s=new Scanner(System.in);
System.out.println("Enter Number");
int x=s.nextInt();
int fib[]=new int [x];
fib[0]=0;
fib[1]=1;
for(int i=2;i<x;i++)
{
fib[i]=fib[i-1]+fib[i-2];
}
for(int se:fib)
{
System.out.print(se+" ");
}
}
}
https://cjavapoint.blogspot.com/?m=1
public class FibonaciiSeries
{
public static void main(String[] args)
{
Scanner s=new Scanner(System.in);
System.out.println("Enter Number");
int x=s.nextInt();
int fib[]=new int [x];
fib[0]=0;
fib[1]=1;
for(int i=2;i<x;i++)
{
fib[i]=fib[i-1]+fib[i-2];
}
for(int se:fib)
{
System.out.print(se+" ");
}
}
}
https://cjavapoint.blogspot.com/?m=1
Blogspot
Core Java Interview Questions - Learn Java
Java Tutorial or Learn Java or Core Java Tutorial or Java Programming Tutorials for beginners and professionals with core concepts and examples
π1