0% found this document useful (0 votes)
17 views

Java Questions1

Uploaded by

Jiju Abutelin Ja
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
17 views

Java Questions1

Uploaded by

Jiju Abutelin Ja
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 17

Q1.What will be the output of the following Java code?

class box

int width;

int height;

int length;

int volume;

box()

width = 5;

height = 5;

length = 6;

void volume()

volume = width*height*length;

class constructor_output

public static void main(String args[])

box obj = new box();

obj.volume();

System.out.println(obj.volume);

}
Ans: 150

Q2.Which of these can be overloaded?


a)Methods

b)Constructors

c)All of the mentioned

d)None of the mentioned

Q3.What is true about constructor?


a)It can contain return type

b)It can take any number of parameters

c)It can have any non access modifiers

d)Constructor cannot throw an exception

Q4.Which of the following is a method having same name as that of it’s


class?
a)finalize

b)delete

c)class

d)constructor

Q5.Which method can be defined only once in a program?


a)main method

b)finalize method

c)static method

d)private method

Q6.What will be the output of the following Java program?


class dynamic_initialization {

public static void main(String args[])

double a, b;

a = 3.0;

b = 4.0;

double c = Math.sqrt(a * a + b * b);

System.out.println(c);

Ans: sqrt(25.0)=5.0

Q7.What will be the output of the following Java code?


class San

public void m1 (int i,float f)

System.out.println(" int float method");

public void m1(float f,int i);

System.out.println("float int method");

public static void main(String[]args)

San s=new San();

s.m1(20,20);

}
}

a)int float method

b)float int method

c)compile time error

d)run time error

Q8.What will be the output of the following Java program?


class box

int width;

int height;

int length;

int volume;

void volume()

volume = width*height*length;

class Output

public static void main(String args[])

box obj = new box();

obj.height = 1;

obj.length = 5;

obj.width = 5;

obj.volume();
System.out.println(obj.volume);

a)0

b)1

c)25

d)26

Q9.What will be the output of the following Java code?


class overload

int x;

int y;

void add(int a)

x = a + 1;

void add(int a, int b)

x = a + 2;

class Overload_methods

public static void main(String args[])

overload obj = new overload();


int a = 0;

obj.add(6);

System.out.println(obj.x);

a)5

b)6

c)7

d)8

Q10.What will be the output of the following Java program?


class box

int width;

int height;

int length;

int volume;

void volume(int height, int length, int width)

volume = width*height*length;

class Prameterized_method

public static void main(String args[])

{
box obj = new box();

obj.height = 1;

obj.length = 5;

obj.width = 5;

obj.volume(3,2,1);

System.out.println(obj.volume);

a)0

b)1

c)6

d)25

Q11.What is the process of defining two or more methods within same class
that have same name but different parameters declaration?
a)Method overloading

b)method overririding

c)method hiding

d)none of the mentioned

Q12.What will be the output of the following Java program?


class area

int width;

int length;

int volume;

area()
{

width=5;

length=6;

void volume()

volume = width*length*height;

class cons_method

public static void main(String args[])

area obj = new area();

obj.volume();

System.out.println(obj.volume);

a)0

b)1

c)30

d)Error

Q13.What will be the output of the following Java program?


class equality

int x;
int y;

boolean isequal()

return(x == y);

class Output

public static void main(String args[])

equality obj = new equality();

obj.x = 5;

obj.y = 5;

System.out.println(obj.isequal());

a)false

b)true

c)0

d)1

Q14.What will be the output of the following Java code?


class area

int width;

int length;
int area;

void area(int width, int length)

this.width = width;

this.length = length;

class Output

public static void main(String args[])

area obj = new area();

obj.area(5 , 6);

System.out.println(obj.length + " " + obj.width);

a)0 0

b)5 6

c)6 5

d)5 5

Q15.What is the process of defining more than one method in a class


differentiated by method signature?
a)Function overriding

b)Function overloading

c)Function doubling
d)None of the mentioned

Q16.What will be the output of the following Java program?


class array_output {

public static void main(String args[])

char array_variable [] = new char[10];

for (int i = 0; i < 10; ++i) {

array_variable[i] = 'i';

System.out.print(array_variable[i] + "" );

i++;

a)i i i i i

b)0 1 2 3 4

c)i j k l m

d)None of the mentioned

Q17.What will be the output of the following Java program?


class mainclass {

public static void main(String args[])

char a = 'A';

a++;

System.out.print((int)a);
}

a)66

b)67

c)65

d)64

Q18.What will be the output of the following Java code?


class increment {

public static void main(String args[])

int g = 3;

System.out.print(++g * 8);

a)25

b)24

c)32

d)33

Q19.Which of these coding types is used for data type characters in Java?
a)ASCII

b)ISO-LATIN-1

c)UNICODE

d)None of the mentioned

Q20.What will be the output of the following Java code?


class booloperators {

public static void main(String args[])

boolean var1 = true;

boolean var2 = false;

System.out.println((var1 & var2));

a)0

b)1

c)true

d)false

Q21.What will be the output of the following Java code?


class average {

public static void main(String args[])

double num[] = {5.5, 10.1, 11, 12.8, 56.9, 2.5};

double result;

result = 0;

for (int i = 0; i < 6; ++i)

result = result + num[i];

System.out.print(result/6);

}
a)16.34

b)16.566666644

c)16.46666666666667

d)16.46666666666666

Q22.Which one is a valid declaration of a boolean?


a)boolean b1 = 1;

b)boolean b2 = ‘false’;

c)boolean b3 = false;

d)boolean b4 = ‘true’

Q23.What will be the output of the following Java program?


class mainclass {

public static void main(String args[])

boolean var1 = true;

boolean var2 = false;

if (var1)

System.out.println(var1);

else

System.out.println(var2);

a)0

b)1

c)true

d)false
Q24.What is the range of short data type(16 bits in memory) in Java?
a)-128 to 127

b)-32768 to 32767

c)-2147483648 to 2147483647

d)None of the mentioned

Q25.What will be the output of the following Java code?


class asciicodes {

public static void main(String args[])

char var1 = 'A';

char var2 = 'a';

System.out.println((int)var1 + " " + (int)var2);

a)162

b)65 97

c)67 95

d)66 98

Q26.What is the range of byte data type(6 bits in memory) in Java?


a)-128 to 127

b)-32768 to 32767

c)-2147483648 to 2147483647

d)None of the mentioned


Q27.What will be the output of the following Java code?
class area {

public static void main(String args[])

double r, pi, a;

r = 9.8;

pi = 3.14;

a = pi * r * r;

System.out.println(a);

a)301.5656

b)301

c)301.56

d)301.56560000

Q28.Method overriding is combination of inheritance and polymorphism?


a)True

b)False

Q29.What is use of interpreter?


a)They convert bytecode to machine language code

b)They read high level code and execute them

c)They are intermediated between JIT and JVM

d)It is a synonym for JIT


Q30.Which concept of Java is achieved by combining methods and attribute
into a class?
a)Encapsulation

b)Inheritance

c)Polymorphism

d)Abstraction

System.out.println("The result "+result + " is of type " +


((Object)result).getClass().getSimpleName());

You might also like