JAVA PROGRAM ALL QUESTIONS ANSWERS
Which of the following is not a Java features?
a) Dynamic
b) Architecture Neutral
0) Use of pointers
d) Object-oriented
Question 2
What should be the execution order, if a class has a method,
static block, instance
block. and constructor, as shown below?
public class First_C {
public void myMethod()
{
Systemout.printin("Method");
}
{
System.out.println(" Instance Block");
}
public void First_C()
{
Systemout.println("Constructor
");
}
static{
System.out.println("static block");
}
public static void main(String[] args) {
First_C c = new First_C();
c.First__C();
cmyMethodO;
}
}
a) instance block, method, static block, and constructor
b) Method, constructor, instance block, and static block
c) Static block, method, instance block, and constructor
d; Static block, instance block, constructor, and method
Question 3
In which process, a local variable has the same name as one
of the instance variables?
a) Serialization
b) Variable Shadowing
c) Abstraction
d) Multi-threading
Question 14
What is Runnable?
3) Abstract class
b) Interface
c) Class
d) Method
Question 15
public class Main
{
public static void main(String[]
args) {
int arr[] =
{'a',‘b','c‘.'d‘.'e'};
System.out.pn‘nt(arr);
}
}
a) abcde
b) 6566676869
c) Compilation Error
d) Some Garbage Value
Question 16
Which of the following is a valid
declaration of a char?
3) char ch = '\utea';
b) char ca = 'tea‘
c) char cr = \u9223;
d) char cc = “titea'; '
Question 17
identity the keyword among the
following that makes a variable belong to a
class,rather than being defined
for each instance of the class.
a) Finat
b) Static
c) Volatile
d) Abstract
Question 18
An abstract class cannot be
instantiated because it contains...
3) Abstract methods
b) Private methods
0) Static methods
d) Public methods
Question 19
Which concept provides a
blueprint for a class?
a) Polymorphism
b) ln'netitance
c) Encapsulation
d) Anstraction
Question 20
Which modifier restricts access to class members within the
same class?
a) public '
in) protected
c) private
d) static
Question 21
WHICH OF the following operator has more precedence?
a) ( )
b) ‘++
c) ‘
d) >=
Question 22
public class CppBuzz {
public static void main(String args[]) {
int a =10:
String b = “10":
System.out.println(a+b);
}
}
a) 10"10"
b) Compilation Error
c) 20
d) 1010
Question 23
Java supports both Primitive & Non-Primitive(User
Defined) datatypes. Which one
of the following is not a primitive datatype?
a) byte
0) short
5) long
6) class
Question 24
Arrays in java are-
a) Object references
b) objects
6) Primitive data type
d) None
Question 25
What is the purpose of the "try" block in
exception handing
a) It catches exceptions and handles them
in) It specifies the exception type
c) It contains the code that might throw an exception
(1) It Specifies the exception message
Question 26
public class CppBuzz {
public static void main(String[] args){
int 3 = 10;
System.out.println(++a*a++);
}
}
a) 121 f
b) 132 j
c) 144 I
d) 100 J
What is the main purpose of access modifiers in Java?
a) To provide default values J
b) To control visibility and access 3
c) To define the class structure
d) To initialize objects
What is the main difference between encapsulation and
abstraction in Java?
a) Encapsulation focuses on hiding data. while abstraction
focuses on hiding I
implementation details.
b) Encapsulation focuses on hiding implementation details,
while abstracti0n
focuses on hiding data
c) Encapsulation and abstraction are the same concepts.
d) Encapsulation and abstraction are unrelated concepts.
What
does the expression float a = 35 / 0 return?
Question 30
How many times 'Hello‘ is printed?
public class TestExam {
public static void main(String[] args){
for(int i = 0; i>5; )
{
System.out.println(“Hello");
}
}
}
a) 5
b) 4
c) 3
d) 0
g
“which of the following is to String() method defined?
Which of the following for loop declaration is
not valid?
public
static void main(String[] args){
Arrays
is a group of similar type of datatype
What
do you mean by nameless objects?
a)
An object created by using the new keyword.
b)
An object of a superclass created in the subclass.
c)
An object without having any name but having a reference.
d)
An object that has no reference
Which
of the following operators has more precedence in Java?
Question 37
When is the object created with new keyword?
3) At Run Time
b) At Compile time
c) Depends on the code
d) None
Question 38
Java is case sensitive Language
a) TRUE
b) FALSE
Question 39
What will be the output of the following program?
public class My First{
public static void main (String|] args){
My First obj = new My First(n);
}
static int 3 = 10;
static int n;
int b = 5;
int c;
public My First (int m) {
System.out.println(a + ", " + b + ", " +
c + ", " + n + ", " + m);
}
/// Instance Block '
{
b = 30;
n = 20;
}
// Static Block
static
{
a = 60;
}
}
a) 10,5,0,20.0
b) 10.30.20
0) 60.5,0.20
d) 60.30,0,20,0
Question 40
What is the purpose of the 'catch' block in exception
handling? '
a) It specifies the exception message
b) It specifies the exception type
c) it catches exceptions and handles them
d) It contains the code that might throw an exception
Which of the following is true about the anonymous inner
class?
a) It has only methods
b) Objects can't be created
c) It has a fixed class name
d) It has no class name
Question 42
public class Main
{
public static void main(String[] args){
int arr[] = {'a','b’,'c','d','e'};
for(int i = 0 ; i<5; i++){
System.out.print(" "+ (char)arr[i]);
}
}
}
a) a b c d e
b) 96 97 98 99101
c) 65 66 67 68 69
d) None of the above
Question 43
public class CppBuzz {
public static void main(String[] args){
int a = 5+5*2+2*2+(2*3);
System.out.println(a);
}
}
a) 138
b) 264
c) 41
d) 25
Question 44
Which of these method of FileReader class is used to read
characters from a file?
a) read()
b) scanf()
C) getl)
d) getinteger()
Question 45
Which one of the following is an Unary operator in Java?
8) ()
b) ‘ .
c) ‘+
d) '++
Select
the valid statement to declare and initialize an array
Which
OOP principle bundles data and methods into a single unit?
Which
method of the Classctass is used to determine the name of a class
represented
by the class object as a String?
How
many times ‘Heilo‘ is printed?
public
static void main(String[| args){
What
is correct sequence of execution of any Java program?
a)
Editing -> Compilation -> Class Loader -> Bytecode Verifier ->
Execution
b)
Editing -> Bytecode Verifier -> Compilation -> Class Loader ->
Execution
c)
Editing -> Compilation -> Briecode Verifier -> Class Loader ->
Exscution
public
static void main(String[] args){
in
Java. which keyword is used to define an abstract class?
Which
of these cannot be used for a variable name in Java?
What
do you mean by >>> operator in Java
What
is a constructor in Java?
a)
A special method to create instances of classes
b)
A method used for mathematical calcuclations
c)
A method to perform string manipulations
d)
An exception handling mechanism
Which
keyword is used to define a method in Java?
Evaluate
the following Java expression, if x=3, y=5, and 2=102
public
static void main(String[] argS) {
Comments
Post a Comment