JAVA PROGRAM ALL QUESTIONS ANSWERS



Questlon 1

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

Question 27

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

Question 28

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.

Question 29

What does the expression float a = 35 / 0 return?

a) 0

b) Not a Number

c) infinity

d) Run time exception

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

 Question 31

g “which of the following is to String() method defined?

a) java.lang.0bject

b) java.lang.String

c) iava.lang.util

d) None

Question 32

 Which of the following for loop declaration is not valid?

a)  for(inti=99;i>=0;i/9)

b)  for(inti=7;i<=77;i+=7)

c) for(inti=20;i>=2;--i)

d) for(inti=2:i<=20;i=2*i)

Question 33

public class Main

{

1 private int a;

public Main(){

3 = —10;

}

public static void main(String[] args){

Main obj = new Main();

System.out.println(obj.a):

 }

}

a) O

b) Compilation Error

c)  -10

(1) Garbage Value

Question 34

Arrays is a group of similar type of datatype

a) True

b) ‘False

Question 35

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

Question 36

Which of the following operators has more precedence in Java?

3) '-

b) '+

c) "

d) '/

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

 Question 41

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) '++

 Question 46

Select the valid statement to declare and initialize an array

a) inti} A={}

b) intfl A={1.2,3}

c) intfi A=(‘l,2.3)

d) intfinA={1.2t3}

Quesh'on 47

Which OOP principle bundles data and methods into a single unit?

al Inheritance

b) Abstraction

c) Encapsulation

d) Polymorphism

Question 48

Which method of the Classctass is used to determine the name of a class

represented by the class object as a String?

3) getCiasst)

b) intern()

c) getNamei)

d) toStn‘ngi)

Qustion 49

How many times ‘Heilo‘ is printed?

public class CppBuzz{

public static void main(String[| args){

forfint i = O; i<5; i=5 )

(

System.out.println("Hello");

}

}

a) 5

b) 4

c) 2

d) 1

Question 50

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

d) None of the above

Question 51

public class CppBuzz{

public static void main(String[] args){

int 3 = 10;

System.out.println(++a'++a);

} _

} .

a) 121

b) 144

c) 132

d) 100

 Question 52

in Java. which keyword is used to define an abstract class?

a) abstract

b) class

6) interface

d) extends

Question 53

Which of these cannot be used for a variable name in Java?

8) identifier & keyword

b) identifier

c) keyword

* d) None of the above

Question 54

What do you mean by >>> operator in Java

3) Left Shift Operator

b) Right Shift Operator

0) Zero Fill Right Shift

d) Zero Fill Left Shift

Question 55

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

Question 56

Which keyword is used to define a method in Java?

8) method

b) def

c) func

d) public

Question 57

Evaluate the following Java expression, if x=3, y=5, and 2=102

++z+y—y+z+x++ ‘

a) 24

b) 23

c) 20

d) 25

Question 53

public class Main

{

public static void main(String[] argS) {

int arrfl = {123,45};

int count = 0:

for(int i = 0 : i<5‘, i++ ){

if(arr[i]%2==0)

count++;

 

Comments

Popular posts from this blog

How Does Crypto Work?

C--PROGRAM ALL QUESTIONS ANSWER