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

Question Bank

Questions
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
63 views

Question Bank

Questions
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 20

QUESTION BANK

PART A
1) Identify the incorrect Java feature.
a) Object oriented
b) Use of pointers
c) Dynamic
d) Architectural neural
2) What does the operator >>>> do?
a) Right shift operator
b) Left shift operator
c) Zero fill left shift
d) Zero fill right shift
3) How many times will “Interviewbit” be printed.

Public class Solution{


Public static void main(String args[]){
Int count = 0;
do{
System.out.println(“Interviewbit”);
count++;
} while(count < 10);}
}

a) 8
b) 9
c) 10
d) 11
4) Find the output of the following code.
Public class Solution{
Public static void main(String args[]){
Int i;
for(i = 1; i < 6; i++){

if(i > 3) continue;


}
System.out.println(i);
}
}

a) 3
b) 4
c) 5
d) 6
5) Find the output of the following code.

Public class Solution{


Public static void main(String… argos){
Int x = 5;
x *= (3 + 7);
System.out.println(x);
}
}

a) 50
b) 22
c) 10
d) None
6) Find the output of the following code.
public class Solution{
public static void main(String[] args){
if(1 + 1 + 1 + 1 + 1 == 5){
System.out.print(“TRUE”);
}
else{
System.out.print(“FALSE”);
}}}

a) TRUE
b) FALSE
c) Compile error
d) None
7) Find the output of the following code.

public class Solution{


public static void main(String[] args){
int ++a = 100;
System.out.println(++a);
}
}

a) 101
b) Compile error as ++a is not valid identifier
c) 100
d) None
8) Identify the output of the following program.
Public class Test{
Public static void main(String argos[]){
String str1 = “one”;
String str2 = “two”;
System.out.println(str1.concat(str2));
}
}

a) one
b) two
c) one two
d) two one
9) Identify the output of the following program.

public class Solution{


public static void main(String[] args){
String str = “abcde”;
System.out.println(str.substring(1, 3));
}
}
a) abc
b) bc
c) bcd
d) cd
10) Find the output of the following program.

public class Solution{


public static void main(String[] args){
byte x = 127;
x++;
x++;
System.out.print(x);
}
}

a) -127
b) 127
c) 129
d) 2
11) Find the value of a[1] after execution of the following program.
public class Main{
public static void main(String[] args){
int[] a = {0,2,4,1,3};
for(int i = 0; i<a.length; i++){
a[i] = a[(a[i] + 3) % a.length];
System.out.println(a[i]);
}
}
}

a) 0 b) 1 c) 2 d) 3
12) Automatic type conversion is possible in which of the possible cases?
a) Byte to Int
b) Int to Long
c)Long to Int
d)Short to Int
13) Find the output of the following code.
public class Main{
public static void main(String[] args){
int Integer = 24;
char String = 'I';
System.out.println(Integer);
System.out.println(String);
}
}
a) Compile error
b) Throws Exception
c)I
d)24I
14) When an array is passed to a method, what does the method receive?
a) Reference of the array
b) A Copy of the array
c) Length of the Array
d) Copy of first element
15) Select the valid statement to declare and initialize an array.
a) int [] A= {}
b) int [] A= {1,2,3}
c) int [] A= (1,2,3)
d) int [] [] A= {1,2,3}
16) Identify the return type of a method that does not return any value.
a) Int
b) Void
c) Double
d) None
17) Identify the infinite loop.
a) for(;;)
b) for(int i=0;i<1;i--)
c) for(int i=0;;i++)
d) All the Above
18) Exception created by try block is caught in which block.
a) Catch
b) Throw
c) Final
d) None
19) Which of the following is not an OOPS concept in Java?
a) Polymorphism
b) Inheritance
c) Compilation
d) Encapsulation
20) What is not the use of “this” keyword in Java?
a) Referring to the instance variable when a local variable has the same
name
b) Passing itself to the method of the same class
c) Passing itself to another method
d) Calling another constructor in constructor chaining
21) Which component is used to compile, debug and execute the java
programs?
a) JRE b) JIT c) JDK d) JVM
22) What will be the output of the following Java program?
int g=3;
System.out.println(++g * 8);
a) 32 b) 33 c) 24 d) 25
23) Which environment variable is used to set the java path?
a) MAVEN_Path b) JavaPATH
c) JAVA d) JAVA_HOME
24) What will be the output of the following Java program?
double a,b,c;
a =3.0/0;
b = 0/4.0;
c = 0/0.0;
System.out.println(b);
a) NaN b) Infinity c) 0.0 d) all of the mentioned
25) What is not the use of “this” keyword in Java?
a) Referring to the instance variable when a local variable has the same
name
b) Passing itself to the method of the same class
c) Passing itself to another method
d) Calling another constructor in constructor chaining
26) What will be the error in the following Java code?
Byte b=50;
b *= 50;
a) b cannot contain value 50
b) b cannot contain value 100, limited by its range
c) No error in this code
d) * operator has converted b * 50 into int, which can not be
converted to byte without casting
27) Which of the following is a type of polymorphism in Java Programming?
a) Multiple polymorphism b) Compile time polymorphism
c) Multilevel polymorphism d) Execution time polymorphism
28) What will be the output of the following Java program?
byte x=64;
int i;
byte y;
i = x << 2;
y = (byte) (x << 2);
System.out.println(i+ “ “ +y);
a) 0 256 b) 0 64 c) 256 0 d) 64 0
29) What is Truncation in Java?
a) Floating-point value assigned to a Floating type
b) Floating-point value assigned to an integer type
c) Integer value assigned to floating type
d) Integer value assigned to floating type
30) What will be the output of the following Java code snippet?
int arr[] = {1,2,3,4,5};
for (int i=0; i<arr.length-2; ++i)
System.out.println(arr[i] + “ “);
a) 1 2 3 4 5 b) 1 2 3 4
c) 1 2 d) 1 2 3
31) What is the output of the following JAVA code?
String s = “exam:” + 9 + 9 + 9;
System.out.println(s);
a) exam:27 b) exam:9 c) exam:27 d) exam:999
32) What is the use of ‘javac’ command?
a) Execute a java program b) Debug a java program
c) Interpret a java program d) Compile a java program
33) Which of the following methods will create a string in Java?
I. String S = “Hello Java”;
II. String S2 = new Strung (“Hello Java”);
a) Only I b) Only II c) Both I & II d) Neither I or II
34) What is the output of the following java code?
int m=1000;
int k=3000;
while (++m < -- k);
System.out.println(m);
a) 2000 b) Error c) 1000 d) 4000
35) Select the valid statement.
a) char[] ch = new char(5); b) char[] ch = new char[5];
c) char[] ch = new char(); d) char[] ch = new char[];
36) Which of the following is NOT a java primitive type?
a) short b) long c) long double d) Boolean
37) A condition that is caused by run-time error in a computer program is
known as:
a) Syntax error b) Fault c) Semantics error d) Exception
38) Additional information sent when an exception is thrown
may be placed in ________
a) The throw keyword b) The function that caused the error
c) The catch block d) An object of the exception class
39) Wrapper class in java is ____________.

a) Used to encapsulate primitive data types


b) Declare new classes called wrapper
c) Create a new instance of the class d) None of these
40) A Enum type in Java is like a _______.
a) Interface b) Class c) abstract class d) None of the above
PART B
1. List out the three ways to get inputs from users in java along with
syntax.
2. Write a simple java program to print “Hello World!” statement
3. What are the principle’s of OOp’s?
4. Enlist all the types if statements.
5. Mention any 5 applications of java.
6. Explain JVM, JRE and JDK
7. Explain static keyword with simple program
8. Enlist all the types for loops.
9. Explain Access Modifiers and Write the access modifiers in the
increasing order of their visibility?
10. What is the usage of “this” keyword in java?
11. Define Auto widening and Explicit Narrowing
12. Explain interface in java along with the simple program
13. Find out the error/s and fill up the incomplete fields/methods in the
below mentioned code to make it an executable program. Also
mention an appropriate output.
class Employee
{
float salary=40000;
}
class extend Employee
{
int bonus=10000
Public static Void main(String args)
{
Programmer p= Programmer();
System.out.println("Programmer salary is:"+p.salary);
System.out("Bonus of Programmer is:"+p.bonus);
}}
14. Differentiate between interface and abstract class.
15. Mention the need and usage of aggregation in java by illustrating an
appropriate program.
16. Differentiate between Method overloading and Method overriding in
java.
17. List out the types of arrays and write a java program by using single
dimensional array with an appropriate output.
18. Name and briefly describe the inheritance type mentioned below:

19. What is meant by Object Oriented Programming?


20. What are Encapsulation, Inheritance and Polymorphism?
21. Explain working of Java Virtual Machine (JVM)?
22. What are the different types of access modifier?
23. Differentiate between a Class and an Object?
24. Explain constructor with simple program?
25. Explain Exception Handling and what are its advantages?
26. Find out the error in the below code and describe about the error.
enum Enums
{
ZERO ,ONE , NINE, ONE, FIVE;
}
27. Find out the error/s and fill up the incomplete fields/methods in the
below mentioned code to make it an executable program. Also mention
an appropriate output.
import java.io.*;
class Bank
{
private name;
// bank name
Bank(string name)
{
this.this.name= name
}
public String getBankName(
{
return this.name
}
}
28. Define java package. Differentiate valid package name and invalid
package name using an example program.
29. Differentiate between final class and final method in java with an
example.
30. Differentiate local variable, instance variable and static variable of java
with a common example.
PART C
1. Write the Outputs for code given below:
public class Sample
{
public static void main(String[] args)
{
int a=10;
int b=5;
int c=20;
System.out.println(a<b&&a<c);
System.out.println(20>>3);
System.out.println(-20>>2);
System.out.println(15<<4);
System.out.println(a--);
System.out.println(--a);
System.out.println(++a);
System.out.println(a++);
}
}
2. Write the Outputs for code given below:

public class Main


{
public static void main(String[] args)
{
for(int i=1;i<=5;i++)
{
for(int j=1;j<=3;j++)
{
if(i= =1&&j= =2)
{
break;
}
System.out.println( j+""+i );
}
}
}
}

3. Enlist all the types of java operators and write the program by using the
operators with an appropriate output.
4. Write a Java program checks whether a driver is eligible for insurance
based on their marital status, gender, and age. The program uses
nested if statements to check for different conditions based on the
driver's marital status.
If the driver is unmarried (marital variable equals 'U' or 'u'), the
program prompts the user to enter their gender and age. If the driver is
male and over 30 or female and over 25, the program prints "You are
Eligible for Insurance". Otherwise, the program prints "You are Not
Eligible for Insurance".
If the driver is married (marital variable equals 'M' or 'm'), the program
assumes that they are eligible for insurance and prints "You are Eligible
for Insurance". If the marital variable is neither 'M' nor 'U', the program
prints "Invalid Input".
Nested if Statement
A company insures its drivers in the following cases:
a. If the driver is married.
b. If the driver is unmarried, male & above 30 years of age.
c. If the driver is unmarried, female & above 25 years of age.

5. Explain all the control statements along with the syntax and also an
example program for the iteration of elements using FOR loop.
6. Write a program with the use of abstract classes and methods in Java.



 The abstract class Car defines two abstract methods brake() and
clutch(), and also has a non-abstract method engine(). Since
the Mobile class is abstract, it cannot be instantiated directly.
 The classes tata and Hyundai extends the Car class and implement its
abstract methods. tata only implements brake() and clutch(), while
Hyundai implements the same methods as well as an additional method
called parking sensor().
 The main method creates objects of both tata and hyndai classes and
calls their respective methods. tata object has access to the engine(),
brake(), and clutch() methods of the Car class, while the
Hyundai object has access to these methods as well as the parking
sensor() method that is specific to the Hyundai class.
Overall, this program demonstrates how abstract classes can be used to define
a set of methods that must be implemented by any concrete class that extends
it, and how these concrete classes can have different implementations of the
abstract methods.
7. Explain constructor, types of constructor, difference between
constructor and method, difference between constructor and destructor
and write program for types of constructor.
8. Explain Inheritance in java, use of inheritance, Syntax of inheritance,
Meaning of extends keyword, types of inheritance with diagram and
define a two separate programs.
a) First program to define inheritance in java with the IS-A relationship
b) Second program to demonstrate the concept of multiple inheritance in java
9. Explain concept of array in java, types of arrays, single dimensional
array and multi-dimensional array along with the java arrays program.
Advantages and Disadvantages of arrays in java.
10. Write a Java program converts all uppercase letters in a given string to
lowercase.
 The program starts by initializing a StringBuilder object a with the
string "XYZ", and it is printed using System.out.println("Original Input
: "+a).
 A for loop is used to iterate through the characters of the string. If the
character is an uppercase letter (its ASCII value is between 65 and 90),
it is converted to lowercase by adding 32 to its ASCII value and then
setting the new character using the setCharAt() method of the
StringBuilder object.
Finally, the updated string is printed
using System.out.println("Lowercase Output: "+a).
11. This Java program implements a toggle case feature on a given string.
The program starts by initializing a StringBuilder object a with the
string "Dhanalakshmisrinivasan University", and it is printed
using System.out.println("Original String : "+a).
 Then, a for loop is used to iterate through all characters of the string. If
the character is lowercase (its ASCII value is between 97 and 122), it is
converted to uppercase by subtracting 32 from its ASCII value and then
setting the new character using the setCharAt() method of the
StringBuilder object. Otherwise, if the character is uppercase (its ASCII
value is between 65 and 90), it is converted to lowercase by adding 32
to its ASCII value and setting the new character using
the setCharAt() method.
Finally, the updated string is printed
using System.out.println("tOGGLEcASEwORDOutput : "+a).
12. Write a program for In this example, there are three
classes GrandFather, father and son. The class father extends
the GrandFather class, while the class son extends the father class.
 The GrandFather class has a method house() which prints the message
"3 BHK House.". The father class has a method land() which prints the
message "5 Arcs of Land..". The son class has a method car() which
prints the message "Own Audi Car..".
 In the main() method, an object o of the son class is created. The car(),
house() and land() methods are called using this object to print their
respective messages. Since son class extends father class which in turn
extends GrandFather class, the son object can access all
the methods of these classes.
13. Explain Exception Handling in java. Difference between throw and
throws.
Difference between final, finally and finalize and write a example
program for exception handling.
14. i) Write a Java program that demonstrates the use of the switch
statement. The program prompts the user to choose an operation to
perform (addition, subtraction, multiplication, or division), and then
prompts the user to enter two numbers. The program then performs the
selected operation on the two numbers and prints the result.
ii) Explain in detail about Static Method and Static Variable in java
with a program.
15. Explain Polymorphism and their types. Define Method Overloading
and Method Over riding and also write the difference between them
16. Explain abstract class in java and mention the ways to achieve
abstraction in java along with a sample program
17. Explain Wrapper Class in Java. List the primitive data types and their
corresponding Wrapper Class.
Write a example program to convert a byte primitive data type to
a Byte object, the program first declares a variable b of type byte and
assigns it the value 10. It then declares a Byte object named bo1 and
initializes it with new Byte(b). This creates a new Byte object with a
value equal to the byte value 10. The program then declares
another Byte object named bo2 and initializes it with Byte.valueOf(s1).
Here, the valueOf method of the Byte class is used to create
a Byte object from a String object s1 containing the value "25".
Write the same examples for converting short, int, long, float, and
double primitive data types to their respective wrapper class objects.
Finally, the program prints the values of all the created wrapper class
objects using System.out.println statements.
18. Write a Java program counts the number of uppercase letters, lowercase
letters, spaces, numbers, vowels, and symbols in a given string using a
StringBuilder
19. Write a java program to calculate area of rectangle and
circle using concept of constructors with an appropriate output.
Hint: Based on the formula you have to get the input from the user’s
for the unknown parameters and have to write two separate programs.
20. a) Write a Java program prompts the user to input a number and then
print out all the integers from 1 up to that number using a while loop.
b)This Java program prompts the user to input a number and then prints
out all the even integers from 2 up to that number using a do-while loop
21. Write a Java program to print numbers between 1 to 100 which are
divisible by 5. Programmer can use control statements and loops
concepts.
Input:
i
Expected Output:
Divided by 5:
5, 10, 15, 20, 25, 30, 35, 40, 45, 50, 55, 60, 65, 70, 75, 80, 85, 90,
95.
22. Developer need to store the date in the form of integer in his database
but the data is in the form of string. So convert a string to an integer
using Java.
Input:
Str1
Expected Output:
Input a number (string): 25
The integer value is: 25
23. Write a java program to calculate area of Triangle and Circle using
concept of constructors with an appropriate output.
Note: Length and breadth of triangle are parameters passed at runtime.
Radius is default value.
24. Write a java program for updating the application related to online
shopping according to the scenario given: Customer adds products
into shopping cart in order to buy them. Options are provided for
adding product, deleting a product (not exactly, just making it null),
printing total amount and displaying all products in cart with their
details. Make sure that cart never overflows.
25. An application has to be created for college portal. All
the students should create their own username and
password. Username should be name of the student
followed by surname. Username should be of
15characters only. Password should be their surname. Write the java
program to find the length of the username and print the password of a
particular user.
Expected Input:
Username: ViratKohli
Expected Output:
Username Length: 10
Password: Kohli
26. Create a class named Final World Cup. Total number of matches played
by a team in World Cup is 14 matches. If the team wins more than 9
matches, they are eligible to play Finals World Cup. Write a java
program to find whether the team is eligible for finals or not.
Expected Output:
Enter the team name: India
Number of matches won: 10
India is eligible for Final World Cup
27. Write a Java program to compute the area of a hexagon.
Area of a hexagon = (6 * s^2)/(4*tan(π/6))
where s is the length of a side
Input:
Input the length of a side of the hexagon: 6
Expected Output:
The area of the hexagon is: 93.53074360871938
28. Briefly describe exception handling keywords by using try, catch,
throw, & finally. Illustrate each keyword according to their usage with
an appropriate example.
29. Enlist the types of arrays and implement a java program using
advanced for loopsfor adding lower type with an output.
30. Update the following application related to online shopping. Customer
adds products into shopping cart in order to buy them. Options are
provided for adding product, deleting a product (not exactly, just
making it null), printing total amount and displaying all products in
cart with their details. Make sure that Cart never overflows.
Hint: Shopping Application contains Cart. Cart contains Products. Product
has its details.

****ALL THE BEST****

You might also like