Java Quiz Questions And Answers For Interviews

Java Programming Tutorials

250+ Java Quiz Questions And Answers For Interviews 2019 from Coding compiler. Test your Core Java and Advanced java knowledge by answering these tricky java quiz interview questions for experienced. Let’s start learning Java interview questions and answers to  prepare for Java quiz interviews. All the best for your future and happy learning.

Java Quiz Interview Questions

Here is the list of Java quiz interview questions and answers, you can click on the below topic link and directly go to the respected section of Java interview questions and answers.

Java Quiz Questions And Answers

  1. Java Primitive Data Types Quiz Interview Questions
  2. Java Variables And Assignment Expressions Quiz Interview Questions
  3. Java Expressions Quiz Interview Questions
  4. Java Object Data Quiz Interview Questions
  5. Java If Statement Quiz Interview Questions
  6. Java One-to-one If Instructions Quiz Interview Questions
  7. Java Counting Loops Quiz Interview Questions
  8. Java Result-driven Loops Quiz Interview Questions
  9. Java Random Quiz Interview Questions
  10. Java Object Oriented Programming Quiz Interview Questions
  11. Java Object References Quiz Interview Questions
  12. Java Strings and Object References Quiz Interview Questions
  13. Java Class Definition Quiz Interview Questions
  14. Java Object Parameters Quiz Interview Questions
  15. Java Increment and Decrement Quiz Interview Questions
  16. Java Inheritance Quiz Interview Questions
  17. Java Abstract Classes Quiz Interview Questions
  18. Java Polymorphism Quiz Interview Questions
  19. Java Swing Frames Quiz Interview Questions
  20. Java GUI Buttons Quiz Interview Questions
  21. Java Action Events Quiz Interview Questions
  22. Java Labels and Text Fields Quiz Interview Questions
  23. Java Components and Layout Quiz Interview Questions
  24. Java JPanels and Box Layout Quiz Interview Questions
  25. Java Multiple Choice Quiz Interview Questions

Related Java Interview Questions And Answers

  1. JDBC Interview Questions
  2. Java Servlet Interview Questions
  3. Java IO Interview Questions
  4. Java String Interview Questions
  5. Java Collections Interview Questions
  6. Java Exceptions Interview Questions
  7. Java OOPS Interview Questions
  8. Core Java Interview Questions
  9. JSF Interview Questions
  10. JSP Interview Questions
  11. JPA Interview Questions
  12. Spring Framework Interview Questions
  13. Spring Boot Interview Questions
  14. Core Java Multiple Choice Questions
  15. 60 Java MCQ Questions And Answers
  16. Aricent Java Interview Questions
  17. Accenture Java Interview Questions
  18. Advanced Java Interview Questions For 5 8 10 Years Experienced
  19. Core Java Interview Questions For Experienced

Java Quiz Interview Questions And Answers

Let’s start learning java quiz interview questions from each category.

Java Primitive Data Types Interview Questions

1. What is a data type ?

a. The calculator of the CPU.
b. A portion of the main memory used to store data.
c. A special scheme to represent values ??in bit patterns.
d. The collection of variables that a program uses.

Ans) C

2. How many bit patterns can a single bit represent?

a. 1
b. 2
c. 4
d. 8th

Ans) B

3. What is a primitive data type in Java ?

a. A method to represent values ??that are so useful that they are an integral part of the language.
b. An easy way to represent numbers.
c. The part of Java that matches the older programming languages.
d. A data type that can not be used as part of an object.

Ans) A

4. Does every variable in Java need a data type?

a. No – only numeric variables need a data type.
b. No – a data type is optional.
c. Yes – all variables are of the same data type.
d. Yes – every variable must be declared with its data type.

Ans) D

5. What is NOT a name of a primitive data type in Java?

a. int
b. float
c. stand-in
d. string

Ans) D

6. Is the value ONE always represented by the same bit sequence?

a. Yes – there is only one “one”, so there is only one bit sequence.
b. No – “one” can be represented by different integer or floating point data types.
c. Yes – it is always stored in one bit.
d. No – the bit pattern changes every time the program starts.

Ans) B

7. Suppose a particular data item does not use a primitive data type. What does it have to be?

a. An object.
b. A number.
c. A literal.
d. A Boolean element.

Ans) A

8. How many digits is the decimal precision of the following number: +1200004.5

a. 4
b. 5
c. 8th
d. Over one million

Ans) C

9. Can chardata be stored in the main memory of the computer?

a. No – computers can only save numbers.
b. No -; the computer can only save patterns.
c. Yes – chardata is stored in a special memory.
d. Yes – a primitive data type is used to save it.

Ans) D

10. In which of the following answers does the number of bits increase from the least (left) to the most (right)?

a. byte long short int
b. int byte short long
c. byte short int long

Ans) C

 

Java Variables And Assignment Expressions Interview Questions

 

1. Which of the following is a reserved word ?

a. apple
b. 7up
c. grandtotal
d. boolean

Ans) D

2. Which of the following is NOT a correct variable name?

a. 2schlecht
b. zero
c. derLetzteWertVonAllen
d. Year 2000

Ans) A

3. Which of the following declarations is NOT correct?

a. double duty;
b. float credit;
c. boolean value = 12;
d. int start = 34, end = 99;

Ans) C

4. What does the following program output?

class question4
{
public static void main (String [] args)
{
int costs = 8;
int number = 5;
System.out.println (“Total cost:” + (cost * number));
}
}
a. Total cost: + 40
b. Total cost: 8 * 5
c. Total cost: 40
d. “Total cost:” 40

Ans) C

5. Which of the following shows the syntax of an assignment statement?

a. variable name = expression ;
b. expression = expression ;
c. expression = variable name ;
d. data type = variable name ;

Ans) A

6. What two steps take place when an assignment statement is executed?

a. (1.) The expression is evaluated and (2.) the result is stored in the variable.
b. (1.) The value is stored in the variable and (2.) the expression is evaluated.
c. (1.) Space is reserved and (2.) the number is written into it.
d. (1.) The variable is evaluated and (2.) the result is saved.

Ans) A

7. What is an expression ?

a. The same as a statement.
b. An expression is a list of instructions that make up a program.
c. An expression is a combination of literals, operators, variables, and parentheses to calculate a value.
d. An expression is a number that is expressed in numbers.

Ans) C

8. Which of the following expressions is NOT correct?

a. 5 + 4
b. (5 * 4) / 2
c. (-12 + (13 + 7) / 2) * 4
d. -12 + (13 + 7) / 2) * 4

Ans) D

9. Which of the following expressions is wrong?

a. (34 – 86) / 3
b. (34 – 86) / -3
c. 34 – 86) / (23 – 3)
d. ((34 – 86) / (23 + 3))

Ans) C

10. What is the value of the following expression?

(2 – 6) / 2 + 9

a. 7
b. 8th
c. 9
d. 10

Ans) A

 

Java Expressions Interview Questions

1. Which of the following is not a correct arithmetic expression?

a. alpha
b. (alpha / impulse) – 12.4
c. alpha (/ impuls – 12.4)
d. ((alpha / impuls) – 12.4)

Ans) C

2. What is an operand?

a. Another name for a number.
b. Another name for an integer.
c. One of the arithmetic symbols like *, +, – and /.
d. A value that an operator acts on.

Ans) D

3. Assuming the following declarations:

short a = 12;
int b = 33;

float x = 2.3;
double y = 3.14;

Which of the following expressions is not evaluated as a floating-point operation?

a. a + x
b. 1.5 + 8.6
c. a + b
d. x / y

Ans) C

4. What is the output of the following program?

class question4
{
public static void main (String [] args)
{
int total cost = 6;
int number = 12;
System.out.println (“Cost per item:” + total cost / number);
}
}

a. Cost per item: .5
b. Cost per item: 0
c. Cost per item: 1
d. Cost per item: +6/12

Ans) B

5. What is the result of the following expression?

(1/2 + 3.5) * 2.0

a. 8.0
b. 8th
c. 7.0
d. 0

Ans) C

6. What is the result of the following expression?

-32 / 6

a. -2
b. -5
c. -5.3333
d. +6

Ans) B

7. What is an expression?

a. The same as a statement.
b. An expression is a set of instructions that form a program.
c. An expression is a combination of literals, operators, variables, and parentheses that are used to calculate a value.
d. An expression is a number represented in numbers.

Ans) C

8. Given the following expression:

(a – x) / (13 – z)

Which of the following is NOT a subexpression.

a. (a – x)
b. (13 – z)
c. a – x
d. x) / (13

Ans) D

9. What is the value of

-32% 6

a. 5
b. -5
c. 2
d. -2

Ans) D

10. Which of the following declarations for the constant PI is correct (assuming that the value is correct)?

a. final PI = 3.14159265358979;
b. final double PI = 3.14159265358979;
c. constant double PI = 3.14159265358979;
d. double PI = 3.14159265358979;

Ans) B

 

Java Object Data Interview Questions

 

1. What is a class?

A. A class is a section of computer memory that contains objects.
B. A class is a section of the hard disk reserved for object-oriented programs.
C. A class is a description of a type of object.
D. A class is part of an object that contains variables.

Ans) C

2. How many objects of a given class can be constructed in a program?

A. Only one object is constructed per run.
B. As many as the program requires.
C. Only one per class.
D. One object per variable.

Ans) B

3. Which of the following is a correct way Stringto construct an object?

A. String alpha (“Hello Quiz!”);
Eg String = “Hello Quiz!” ;
C. String alpha = new “Hello Quiz!” ;
D. String alpha = new String (“Hello Quiz!”);

Ans) D

4. What is an object?

A. An object is a piece of memory that may contain data along with methods to process the data.
B. An object is a very small location that contains only data.
C. “Object” is another word for “Program.”
D. An object is a description of a potential class.

Ans) A

5. Do any objects exist at the moment a program is about to start?

A. Yes. All objects describing the program are generated when the program starts to start.
B. Yes. All objects describing the program are generated when the program is compiled.
C. no. Objects are a way of thinking about programming, but they do not really exist.
D. No. Objects are created one at a time when the program is running.

Ans) D

6. Which of the following calls the method of length()the object strreferenced by and stores the result in wert?

A. value = str.length ();
Eg value = length.str ();
C. value = length (). Str;
D. value = length (str);

Ans) A

7. Check the following:

String myString;
What is myString?

A. myString is a reference variable.
B. myString is an object.
C. myString always points to an object.
D. myString is a String.

Ans) A

8. What is a reference to an object?

A. One of the methods of the object.
B. One of the variables of the object.
C. Data where the object can be found.
D. A place in a program that creates the object.

Ans) C

9. Check the following:

String stringA = “Olde Frothingslosh”;
String stringB;

stringB = stringA.substring (6);
Which characters are in the one Stringto which stringBreferences?

A. Olde
B. Froth
C. rothingslosh
D. Frothingslosh

Ans) C

10. What is the class of the type wrapper for the primitive type int?

A. int
B. INT
C. Integer
D. integer

Ans) C

 

Java If Statement Interview Questions

1. How many alternatives are there for a single if-else statement?

a. 1
b. 2
c. 3
d. 4

Ans) B

2. What is the following code snippet on the screen?

int sum = 14;
if (sum <20)
System.out.print (“Below”);
else
{
System.out.print (“About”);
System.out.println (“the limit.”);
}

a. Under
b. Over
c. Under the limit.
d. Over the limit.

Ans) A

3. What is the following code snippet on the screen?

int sum = 7;
if (sum > 20)
{
System.out.print (“You win”);
}
else
{
System.out.print (“you lose”);
}

System.out.println (“the price.”);

(Note that the program has changed!)

a. You win
b. They are losing
c. You win the prize.
d. You lose the price.

Ans) D

4. What is the following code snippet on the screen?

int sum = 21;
if (sum ! = 20)
System.out.print (“You win”);
else
System.out.print (“you lose”);

System.out.println (“the price.”);

(Note that the program has changed!)

a. You win
b. They are losing
c. You win the prize.
d. You lose the price.

Ans) C

5. Evaluate the following expressions ( true or false ):

14 <= ??14 14 <14 -9> -25 -25> -9

a. true true true true
b. true false false false
c. true false true true
d. true false true false

Ans) D

 

Java One-to-one If Instructions Interview Questions

1. Rate the following expression:

1 + 2 == 3

A. true
B. false
C. unpredictable

Ans) A

2. Rate the following expression:

25 <5 * 5

A. true
B. false
C. unpredictable

Ans) B

3. Rate the following expression:

8 + 1> = 3 * 3
A. true
B. false
C. unpredictable

Ans) A

4. What is the following code snippet on the screen?

int height = 10;
if (high <= 12)
System.out.print (“Low Bridge:”);
System.out.println (“Carefully drive on.”);

a. Nothing is spent.
b. Low bridge:
c. drive on carefully.
d. Low bridge: continue driving carefully.

Ans) D

5. What is the following code snippet on the screen?

int height = 13;
if (high <= 12)
{
System.out.print (“Low Bridge:”);
System.out.println (“Carefully drive on.”);
}

a. Nothing is spent.
b. Low bridge:
c. drive on carefully.
d. Low bridge: continue driving carefully.

Ans) A

6. What is the following code snippet on the screen?

int deep = 8;
if (depth> = 8)
{
System.out.print (“Danger”);
System.out.print (“Deep Water.”);
}
System.out.println (“swimming prohibited.”);

a. Danger:
b. Danger: Deep water.
c. Deep water. Swimming prohibited.
d. Danger: Deep water. Swimming prohibited.

Ans) D

7. Rate the following expression:

10.0 + 0.1 <11.0

A. true
B. false
C. unknown

Ans) A

8. Rate the following expression:

10.0 + 0.1> 10.0

A. true
B. false
C. unknown

Ans) A

9. Rate the following expression:

1.0 + 1.0 / 10.0 <1.1

A. true
B. false
C. unknown

Ans) C

10. Fill in the gap so that people under the age of 21 get grape juice.

if (age _________ 21)
System.out.println (“How about a coffee?”);
else
System.out.println (“Grape Juice Filled?”);

a. <
b. ==
c. ! =
d. > =

Ans) D

 

Java Counting Loops Interview Questions

1. Which three parts of a counting loop need to be coordinated in the right order for the loop to work properly?

a. Initialize counter, test counter, change counter
b. Initialize condition, change condition, end loop
c. The whilestatement, the assignment, the loop body
d. The whilestatement, the ifstatement, the sequential execution

Ans) A

2. Another word for ‘looping’ is:

a. recapitulation
b. Tintinabulation
c. iteration
d. reiteration

Ans) C

3. What constitutes a counting loop?

a. A loop whilecontrol variable is tested in the statement and is changed every loop.
b. A count variable is incremented by one until a certain value is reached.
c. A count variable is counted down by one until the value 0 is reached.
d. No loop control variables are used.

Ans) A

4. Consider the following code:

int counter = 0;
while (count <= 6)
{
System.out.print (counter + “”);
counter = counter + 2;
}
System.out.println ();

What is this code on the screen?

a. 1 2 3 4 5 6
b. 0 2 4 6 8
c. 0 2 4
d. 0 2 4 6

Ans) D

5. Consider the following code:

int counter = 7;
while (count> = 4)
{
System.out.print (counter + “”);
counter = counter – 1;
}
System.out.println ();

What is this code on the screen?

a. 1 2 3 4 5 6 7
b. 7 6 5 4
c. 6 5 4 3
d. 7 6 5 4 3

Ans) B

6. Consider the following code:

int counter = -2;
while (count <3)
{
System.out.print (counter + “”);
counter = counter + 1;
}
System.out.println ();

What is this code on the screen?

a. -2 -1 1 2 3 4
b. -2 -1 1 2 3
c. -3 -4 -5 -6 -7
d. -2 -1 0 1 2

Ans) D

7. Consider the following code:

int counter = 1;
while (count <5)
{
System.out.print (counter + “”);
}
System.out.println ();

What is this code on the screen?

a. 1 2 3 4
b. 1 2 3 4 5
c. 2 3 4
d. 1 1 1 1 1 1 1 1 1 1 1. , , ,

Ans) D

8. Consider the following code:

int counter = 1;
while (___________)
{
System.out.print (counter + “”);
counter = counter + 1;
}
System.out.println ();

Which condition should be used for the code to output:

1 2 3 4 5 6 7 8
a. counter <8
b. counter <9
c. counter + 1 <= 8
d. counter! = 8

Ans) B

9. In which of the following situations will most likely no counting loop be used?

a. Addition of the numbers between 0 and hundred.
b. Output of a table with Fahrenheit and its corresponding Celsius values.
c. Prompt the user until a correct entry has been made.
d. Ten-time output of the computer sound signal.

Ans) C

10. What is the most common programming error?

a. The ” wrong-way ” problem where a if-elsestatement is misspelled.
b. The ” wrong operator ” problem where an arithmetic expression does not mean what the programmer thought.
c. The ” uninitialized variable ” problem where a variable is used in an expression before it is initialized.
d. The ” off-by-one ” problem where a count loop executes the instructions in the loop body too much or too little.

Ans) D

 

Java Result-driven Loops Interview Questions

1. Which three types of loops can be formed with the while statement and other instructions?

a. Counting loops, monitoring controlled loops, result controlled loops.
b. Increasing loops, decreasing loops.
c. if- while loops, loops, counting loops.
d. Head-controlled loops, result-controlled loops, foot-controlled loops.

Ans) A

2. Which of the following tasks will most likely use a counting loop?

a. Check for items with a price below $ 125 in an item list.
b. Ask the user at the end of a game if he wants to continue playing.
c. Check if an integer is even or odd.
d. Testing different letter combinations until an encrypted message can be read.

Ans) A

3. Which of the following tasks will most likely use a watch-driven loop?

a. Check for items with a price below $ 125 in an item list.
b. Ask the user at the end of a game if he wants to continue playing.
c. Check if an integer is even or odd.
d. Testing different letter combinations until an encrypted message can be read.

Ans) B

4. For which of the following tasks will you most likely use a result-driven loop?

a. Check for items with a price below $ 125 in an item list.
b. Ask the user at the end of a game if he wants to continue playing.
c. Check if an integer is even or odd.
d. Testing different letter combinations until an encrypted message can be read.

Ans) D

5. Here is a part of a graphics program that simulates the fading of colors in the sun. The red portion starts with a maximum of 1.0 and decreases by 1% for each loop pass until it reaches almost zero.

float red fraction = 1.0;
while (__________________)
{
Red component = red component * 0.99;

// the new red part is used by some graphics methods
}

Select a condition for the whilestatement.

a. Red fraction == 0.0
b. Red component> 0.001
c. Math.abs (red fraction) <0.0
d. red content * red fraction <1.0

Ans) B

6. It is (unfortunately) very easy to write a result-controlled loop trying to reach a goal that is too perfect to ever reach. What happens in this case?

a. The program can not be compiled.
b. The program can be compiled, but it does not work.
c. The program compiles and runs forever.
d. The program compiles, but calculates a completely wrong result.

Ans) C

7. When the operating system writes data to the hard drive, the hard drive is often unwilling and does not accept data. The operating system must try repeatedly until the data is accepted. Which type of loop is this?

a. Monitoring controlled.
b. Counting loop.
c. Hard disk controlled.
d. Result controlled.

Ans) D

8. One rabbit colony will double its population every 28 days. The population starts at 2 and multiplies until it reaches 100,000. Let’s say that this process is simulated by a program. Which of the following while statements will most likely be used for this?

a. while (population = 100000)
b. while (population <100000)
c. while (population! = 100000)
d. while (population <1.0E + 6)

Ans) B

9. To make sure that a number is positive, we determine what value:

a. current value
b. real value
c. absolute value
d. Mega value

Ans) C

10. Consider the following code snippet:

int j = 1;
while (j <10)
{
System.out.print (j + “”);
j = j + j% 3;
}

What is being displayed on the screen?

a. 1 4 7
b. 1 4 7 10
c. 1 2 5 8
d. 1 2 4 5 7 8

Ans) D

 

Java Random Quiz Interview Questions

1. If a source of random numbers produces every number in its range the same number of times, is the distribution of numbers called _________________?

A. equally distributed
B. unevenly distributed
C. just
D. same

Ans) A

2. What are pseudo-random numbers as they are Random generated?

A. Pseudorandom numbers are numbers with various additional features.
B. Pseudo-random numbers are numbers that result in an equal distribution.
C. Pseudorandom numbers are less predictable than true random numbers.
D. Pseudo-random numbers look like random numbers in most applications, but they are generated by an algorithm and are completely predictable if you know the starting value.

Ans) D

3. What does seed mean for a pseudo-random number generator?

A. seed names the random number generator.
B. seed initializes a particular stream of pseudorandom numbers that the generator generates.
C. seed determines the range of numbers the generator generates.
D. seed determines how many random numbers are generated.

Ans) B

4. Assuming that a random number Random rand = Random()generator was created. Which of the following selects an integer from the range 0, 1, 2, 3, 4, 5, 6, 7, 8, 9?

A. rand.nextInt(9)
B. rand.nextInt()*10
C. rand.nextInt(1,10)
D. rand.nextInt(10)

Ans) D

5. Assuming that a random number generator was created with Random rand = Random(). Which of the following selects an integer from the range 10, 11, 12, 13, 14, 15?

A. rand.nextInt(5)
B. rand.nextInt(6) + 10
C. rand.nextInt(10,15)
D. rand.nextInt(5) + 9

Ans) B

6. Which range of values ??is nextInt()generated by?

A. All positive integers.
B. All integers, both negative, zero and positive.
C. Integer from 1 to 100.
D. Integer from 0 to 99.

Ans) B

7. When new Random()a new object is created, what is the basis for the generation of the random numbers.

A. A random seed is selected by the system.
B. A default start value.
C. The current time in milliseconds.
D. The same as the starting value used previously.

Ans) C

8. Which range of values ??is the output of nextDouble()?

A. All double precision floating point values, negative and positive.
B. All positive double precision floating point values.
C. Double precision floating point values ??from -1.0 to 1.0.
D. Double precision floating point values ??from 0.0 to almost 1.0.

Ans) D

9. Which of the following statements select floating point values ??in the range of -10.0 to 15.5 without?

A. rand.nextDouble(-10,15.5)
B. 25.5*rand.nextDouble() – 10.0
C. 15.5*rand.nextDouble() – 10.0
D. rand.nextDouble(15.5) – 10.0

Ans) B

10. A teacher wants a random choice of A, B, C, D and D for a multiple choice test. Which of the following instructions can be used for this?

A.
Random rand = new Random ();
, , ,
char answer = “ABCDE” .charAt (rand.nextInt ());

B.
Random rand = new Random ();
, , ,
char answer = “ABCDE” .charAt (rand.nextInt (6));

C.
Random rand = new Random ();
, , ,
char answer = “ABCDE” .charAt (rand.nextInt (5));

D.
Random rand = new Random ();
, , ,
char answer = “ABCDE” .rand.nextInt (4);

Ans) C

1. If a source of random numbers produces every number in its range the same number of times, is the distribution of numbers called _________________?

A. equally distributed
B. unevenly distributed
C. just
D. same

Ans) A

2. What are pseudo-random numbers as they are Random generated?

A. Pseudorandom numbers are numbers with various additional features.
B. Pseudo-random numbers are numbers that result in an equal distribution.
C. Pseudorandom numbers are less predictable than true random numbers.
D. Pseudo-random numbers look like random numbers in most applications, but they are generated by an algorithm and are completely predictable if you know the starting value.

Ans) D

3. What does seed mean for a pseudo-random number generator?

A. seed names the random number generator.
B. seed initializes a particular stream of pseudorandom numbers that the generator generates.
C. seed determines the range of numbers the generator generates.
D. seed determines how many random numbers are generated.

Ans) B

4. Assuming that a random number Random rand = Random()generator was created. Which of the following selects an integer from the range 0, 1, 2, 3, 4, 5, 6, 7, 8, 9?

A. rand.nextInt(9)
B. rand.nextInt()*10
C. rand.nextInt(1,10)
D. rand.nextInt(10)

Ans) D

5. Assuming that a random number generator was created with Random rand = Random(). Which of the following selects an integer from the range 10, 11, 12, 13, 14, 15?

A. rand.nextInt(5)
B. rand.nextInt(6) + 10
C. rand.nextInt(10,15)
D. rand.nextInt(5) + 9

Ans) B

6. Which range of values ??is nextInt()generated by?

A. All positive integers.
B. All integers, both negative, zero and positive.
C. Integer from 1 to 100.
D. Integer from 0 to 99.

Ans) B

7. When new Random()a new object is created, what is the basis for the generation of the random numbers.

A. A random seed is selected by the system.
B. A default start value.
C. The current time in milliseconds.
D. The same as the starting value used previously.

Ans) C

8. Which range of values ??is the output of nextDouble()?

A. All double precision floating point values, negative and positive.
B. All positive double precision floating point values.
C. Double precision floating point values ??from -1.0 to 1.0.
D. Double precision floating point values ??from 0.0 to almost 1.0.

Ans) D

9. Which of the following statements select floating point values ??in the range of -10.0 to 15.5 without?

A. rand.nextDouble(-10,15.5)
B. 25.5*rand.nextDouble() – 10.0
C. 15.5*rand.nextDouble() – 10.0
D. rand.nextDouble(15.5) – 10.0

Ans) B

10. A teacher wants a random choice of A, B, C, D and D for a multiple choice test. Which of the following instructions can be used for this?

A.
Random rand = new Random ();
, , ,
char answer = “ABCDE” .charAt (rand.nextInt ());

B.
Random rand = new Random ();
, , ,
char answer = “ABCDE” .charAt (rand.nextInt (6));

C.
Random rand = new Random ();
, , ,
char answer = “ABCDE” .charAt (rand.nextInt (5));

D.
Random rand = new Random ();
, , ,
char answer = “ABCDE” .rand.nextInt (4);

Ans) C

 

Java Object Oriented Programming Interview Questions

Java Objects Quiz Questions

1. Which attributes have real existing objects?

a. Objects have an identity, a state and a behavior.
b. Objects have a state and a behavior.
c. Objects have a size and weight.
d. Objects have an existence.

Ans) A

2. Which properties do all software objects have?

a. Software objects have RAM, ROM and processors.
b. Software objects have an identity, a state, and a behavior.
c. Software objects have variables and memory.
d. Software objects are made of computer elements.

Ans) B

3. What is the defining characteristic of a von Neumann computer ?

a. RAM is used for data and ROM for programs.
b. He has both a processor and a memory.
c. Multi-purpose memory is used to store programs and data.
d. He uses general purpose arithmetic registers.

Ans) C

4. If you start a Java application by java IrgendeineKlassetyping, which is the first method that will be executed?

a. The method of main()the class IrgendeineKlasse.
b. The method of run()the class IrgendeineKlasse.
c. The method IrgendeineKlasse.
d. The method applet().

Ans) A

5. What is a class?

a. A class is a piece of computer memory that contains objects.
b. A class is a part of the hard disk reserved for object-oriented programs.
c. A class is the part of an object that contains variables.
d. A class is a description of a type of object.

Ans) D

6. What is another name for object creation?

a. instantiation
b. insubordination
c. initialization
d. heredity

Ans) A

7. What are static variables and methods of a class?

a. Variables and methods that form the basis of each object of the class.
b. Variables and methods that belong to all objects in the computer system.
c. Variables and methods that belong only to the objects of this class.
d. Variables and methods that are part of the class definition but not their objects.

Ans) D

8. Which of the following statements invokes the method of length()the object strand stores the result in the variable laenge?

a. length = str.length ();
b. length = length.str ();
c. length = length (). str;
d. length = length (str);

Ans) A

9. How many objects can an application create from a particular class?

a. Only one per constructor.
b. As many as the application requires.
c. Only one per class.
d. One object per variable.

Ans) B

10. Which of the following instructions is correct?

a. String alpha (“Hello Quiz!”);
b. String = “Hello Quiz!”;
c. String alpha = new “Hello Quiz!”;
d. String alpha = “Hello Quiz!”;

Ans) D

 

Java Object References Interview Questions

1. Consider the following declarations:

int area;
String name;

Which of the following statements is true?

a. flaecheis a primitive variable and nameis a reference variable .
b. flaecheis a reference namevariable and is a primitive variable.
c. Both are primitive variables.
d. Both are reference variables.

Ans) A

2. Consider the following lines of code:

int area;
String name;

How many objects were created?

a. None – there is an object reference variable, but no object yet.
b. One – there is an object reference variable, so there must be an object.
c. Two – one for each variable.
d. Two – one for each guy.

Ans) A

3. Consider the following lines of code:

String strA;
String strB = new String (“biscuits”);

How many objects were created?

a. zero
b. one
c. two
d. three

Ans) B

4. What is displayed on the screen by the following code part:

String strA;
String strB = new String (“biscuits”);

System.out.print (strB);
strA = new String (“Schoko”);
System.out.println (strA);

a. Cookies
b. chocolate
c. Biscuits chocolate
d. Chocolate biscuit

Ans) C

5. What is displayed on the screen by the following code part:

String strA = new String (“Geroestete”);
String strB = new String (“Chestnuts”);

strA = strB;
System.out.print (strA);
System.out.println (strB);

a. Roasted chestnuts
b. Chestnuts roasted
c. Roasted roasted
d. Chestnuts chestnuts

Ans) D

6. What is displayed on the screen by the following code part:

String strA = new String (“Geroestete”);
String strB = new String (“Chestnuts”);

strA = strB;
if (strA == strB)
System.out.println (“Two copies of a reference.”);
else
System.out.println (“Two different references.”);

a. Two copies of a reference.
b. Two different references.
c. Two copies of a reference.
Two different references.
d. Roasted chestnuts references.

Ans) A

7. Consider the following code part:

String strA = new String (“Geroestete”);
String strB = new String (“Chestnuts”);

strA = strB;

How many objects were created? After the last instruction has been executed, how many objects can be reached (without counting the data)?

a. generated: 0 now available: 0
b. generated: 2 now available: 1
c. generated: 1 now available: 1
d. generated: 2 now available: 2

Ans) B

8. Consider the following piece of code:

String strA = new String (“Geroestete”);
strA = new String (“toasted”);
strA = new String (“Grilled”);
strA = new String (“Baked”);
strA = new String (“beans”);

How many objects (in total) were generated? After the last instruction has been executed, how many objects can be reached (without counting the data)?

a. This code part is not correct.
b. generated: 5 now available: 5
c. generated: 1 now available: 1
d. generated: 5 now available: 1

Ans) D

9. Consider the following piece of code:

String strA = new String (“Geroestete”);
String strB = new String (“toasted”);
String strC = new String (“Grilled”);
String strD = new String (“Baked”);
String strE = new String (“Beans”);

How many objects (in total) were generated? After the last instruction has been executed, how many objects can be reached (without counting the data)?

a. This code part is not correct.
b. generated: 5 now available: 5
c. generated: 1 now available: 1
d. generated: 5 now available: 1

Ans) B

10. Consider the following piece of code:

String strA = new String (“Geroestete”);
String strB = strA;
String strC = strA;
String strD = strA;
String strE = strA;

How many objects (in total) were generated? After the last instruction has been executed, how many objects can be reached (without counting the data)?

a. This code part is not correct.
b. generated: 5 now available: 5
c. generated: 1 now available: 1
d. generated: 5 now available: 1

Ans) C

 

Java Object References Interview Questions

1. Consider the following declarations:

int area;
String name;

Which of the following statements is true?

a. flaecheis a primitive variable and nameis a reference variable .
b. flaecheis a reference namevariable and is a primitive variable.
c. Both are primitive variables.
d. Both are reference variables.

Ans) A

2. Consider the following lines of code:

int area;
String name;

How many objects were created?

a. None – there is an object reference variable, but no object yet.
b. One – there is an object reference variable, so there must be an object.
c. Two – one for each variable.
d. Two – one for each guy.

Ans) A

3. Consider the following lines of code:

String strA;
String strB = new String (“biscuits”);

How many objects were created?

a. zero
b. one
c. two
d. three

Ans) B

4. What is displayed on the screen by the following code part:

String strA;
String strB = new String (“biscuits”);

System.out.print (strB);
strA = new String (“Schoko”);
System.out.println (strA);

a. Cookies
b. chocolate
c. Biscuits chocolate
d. Chocolate biscuit

Ans) C

5. What is displayed on the screen by the following code part:

String strA = new String (“Geroestete”);
String strB = new String (“Chestnuts”);

strA = strB;
System.out.print (strA);
System.out.println (strB);

a. Roasted chestnuts
b. Chestnuts roasted
c. Roasted roasted
d. Chestnuts chestnuts

Ans) D

6. What is displayed on the screen by the following code part:

String strA = new String (“Geroestete”);
String strB = new String (“Chestnuts”);

strA = strB;
if (strA == strB)
System.out.println (“Two copies of a reference.”);
else
System.out.println (“Two different references.”);

a. Two copies of a reference.
b. Two different references.
c. Two copies of a reference.
Two different references.
d. Roasted chestnuts references.

Ans) A

7. Consider the following code part:

String strA = new String (“Geroestete”);
String strB = new String (“Chestnuts”);

strA = strB;

How many objects were created? After the last instruction has been executed, how many objects can be reached (without counting the data)?

a. generated: 0 now available: 0
b. generated: 2 now available: 1
c. generated: 1 now available: 1
d. generated: 2 now available: 2

Ans) B

8. Consider the following piece of code:

String strA = new String (“Geroestete”);
strA = new String (“toasted”);
strA = new String (“Grilled”);
strA = new String (“Baked”);
strA = new String (“beans”);

How many objects (in total) were generated? After the last instruction has been executed, how many objects can be reached (without counting the data)?

a. This code part is not correct.
b. generated: 5 now available: 5
c. generated: 1 now available: 1
d. generated: 5 now available: 1

Ans) D

9. Consider the following piece of code:

String strA = new String (“Geroestete”);
String strB = new String (“toasted”);
String strC = new String (“Grilled”);
String strD = new String (“Baked”);
String strE = new String (“Beans”);

How many objects (in total) were generated? After the last instruction has been executed, how many objects can be reached (without counting the data)?

a. This code part is not correct.
b. generated: 5 now available: 5
c. generated: 1 now available: 1
d. generated: 5 now available: 1

Ans) B

10. Consider the following piece of code:

String strA = new String (“Geroestete”);
String strB = strA;
String strC = strA;
String strD = strA;
String strE = strA;

How many objects (in total) were generated? After the last instruction has been executed, how many objects can be reached (without counting the data)?

a. This code part is not correct.
b. generated: 5 now available: 5
c. generated: 1 now available: 1
d. generated: 5 now available: 1

Ans) C

 

Java Strings and Object References Interview Questions

1. What kind of thing is “nothing new” in the following statement: String str = “Nichts Neues”;

a. A string shortcut.
b. A string literal.
c. A string in quotation marks.
d. An optimized string.

Ans) B

2. Consider the code:

String myString;

What is the data type of myString?

a. String
b. Reference toString
c. zero
d. object

Ans) B

3. Which value is assigned to a reference value to show that there is no object?

a. 0
b. void
c. zero
d. “”

Ans) C

4. Consider the code:

String myString = “”;
Which value does it contain myString?

a. zero
b. a reference to a string
c. an empty reference
d. a character reference

Ans) B

5. What happens to an object that no longer has reference variables that reference it?

a. It remains in main memory forever.
b. It is swapped out to the hard disk.
c. The garbage collection service exposes the memory it occupies to other objects.
d. It comes in the dumpster.

Ans) C

6. Consider the code:

String stringA = “Wild”;
String stringB = “Irish”;
String stringC = “Rose”;
String result;

Which of the following statements assigns the variable resulta reference to “Wild Irish Rose”?

a. result = stringA.concat( stringB.concat( stringC ) );
b. result.concat( stringA, stringB, stringC );
c. result+stringA+stringB+stringC;
d. result = concat(StringA).concat(StringB).concat(StringC)

Ans) A

7. If an operator like “+” has more meaning depending on the context, is it called?

a. overloading
b. overload
c. Revise
d. oversize cargo

Ans) A

8. What is the name of an object that can not be changed after creation?

a. unalterable
b. forever
c. invariable
d. incomprehensible

Ans) C

9. What is the result of the following instructions:

String stringA = “Wild”;
String stringB = “Irish”;
String stringC = “Rose”;

String result = stringA.trim () + stringB + stringC.trim ();

a. “WildIrishRose”
b. ” Wild Irish Rose ”
c. “Wild Irish Rose”
d. “Wild Irish Rose”

Ans) D

10. What is the result of the following instructions:

String ring = “A ring to enshrine them all, \ n”
String find = “A ring to find them all.”

if (ring.startsWith (“one”) && find.startsWith (“one”))
System.out.println (ring + find);
else
System.out.println (“Different Start”);

a.
A ring to enslave them all
A ring to find them all.

b.
A ring to enslave them all, A ring to find them all.

c.
A ring to slave them all, \ n
A ring to find them all.

d.
Different beginning

Ans) A

 

Java Class Definition Interview Questions

1. Why is the main()method special in a Java program?

a. Here the Java interpreter starts the whole program.
b. Only the main()method can create objects.
c. Each class must have a main()method.
d. The main()method may be the only static method in a program.

Ans) A

2. Which of the following is a general schema of a class definition:

a.
Class class name
{
// Description of the instance variables.

// Description of the constructors.

// Description of the methods.
}

b.
class class name
{
// Description of the instance variables.

// Description of the constructors.

// Description of the methods.
}

c.
class name
{
// Description of the instance variables.

// Description of the constructors.

// Description of the methods.
}

d.
class class name
{
public static void main (String [] args)
{
// here comes the whole program

}

}

Ans) B

3. Here is the general syntax of a method definition:

access-modifier return-type method-name (parameter-list)
{
instructions

return return value ;
}

What’s right for the access modifier?

a. he always has to privateor publicbe.
b. He can be left out, but if he is not left out he has to be privateor publicbe.
c. It can be omitted, but if he is not left out, there are several options including privateand public.
d. The access modifier must match the type of the return value.

Ans) C

4. If the access modifier is missing in the definition of a class member (instance variable or method), does the member have …..?

a. Standard access.
b. public access.
c. private access.
d. universal access.

Ans) A

5. Here is the general syntax of a method definition:

access-modifier return-type method-name (parameter-list)
{
instructions

return return value ;
}

What is true for the return type and the return value

a. The return value must be exactly the same type as the return type.
b. The return value must be of the same type as the return type or of a type that can be converted to the return type without loss of information.
c. The return value can be of any type, but it is automatically converted to the return type when the method returns to the caller.
d. If the return type voidis, then the return value can be of any type.

Ans) B

6. Which term is used to hide object details?

a. Obfustikation.
b. Data Mining.
c. Compilation.
d. Encapsulation.

Ans) D

7. What effect does it have if a class element (variable or method) has the modifier private?

a. If a class member is privatedeclared as , it can only be used at one point in the program.
b. If a class member is privatedeclared as , it can only be used by methods that are members of the class.
c. If a class member is privatedeclared as , it can only be used by private members of other classes.
d. If a class member is privatedeclared as a member , it will only have one instance, no matter how many objects are instantiated.

Ans) B

 

Java Object Parameters Interview Questions

1. What is a current parameter?

a. The identifier used in a method instead of the value passed to this method by the caller.
b. The value passed to a method by the caller.
c. A variable used to control a counting loop.
d. The value returned by a method.

Ans) B

2. Which type of parameter passing is used in Java?

a. Call-by-value.
b. Call-By-Object.
c. Call-By-parameters.
d. Call-By-Waiting.

Ans) A

3. Will there be any effect on the caller when a method assigns a new value to a primitive parameter?

a. No, because all methods have a copy of the value of the caller.
b. No, as the method is not allowed to change the value of any parameter.
c. Yes, the change will affect the corresponding value of the caller.
d. Yes, because the method and its caller share the same memory section.

Ans) A

4. Does it have any effect on the caller when a method assigns a new object to an object reference parameter?

a. No, as this does not affect any objects that the caller can reference.
b. No, because this is not a legal operation.
c. Yes, because now the caller can reference the new object.
d. Yes, because the new object will replace one of the caller’s objects.

Ans) A

5. Does it have any effect on the caller if a method assigns a new value to an object element that it can access through an object reference parameter?

a. No, since she only has one copy of the object.
b. No, as it is not allowed to do that.
c. Yes, this will change the part of the object that both the method and the caller reference.
d. Yes, the caller will now get a new object.

Ans) C

6. How can a method return a primitive value to the caller?

a. It can assign the value to one of its parameters.
b. It can return the value to the caller by using the returnstatement.
c. A method can under no circumstances communicate with the caller.
d. It can call its caller with the correct value.

Ans) B

7. If a method has a reference to an unchangeable object (eg string object), can the method then make a change to the object?

a. No, immutable objects can not be changed by anyone after they are created.
b. No, only the generator of the immutable object can change it.
c. Yes, if she has a reference to the immutable object, she can change it.
d. Yes, but she has to use the special “+” operator to do that.

Ans) A

8. Can a programmer (you) design a class whose objects are immutable?

a. No, only a few predefined Java classes Stringare immutable.
b. No, all predefined classes are immutable and all classes defined by the programmer are not.
c. Yes, by privatedeclaring all instance variables of the class as declared and no accessor methods.
d. Yes, by privatedeclaring all instance variables and methods as .

Ans) C

9. How many references can there be to a single object?

a. Just one.
b. Two. One from the caller and one from the called method.
c. Three. The original reference and a reference for the formal and the current parameters.
d. There can be any number of references held in any number of variables and parameters (as long as they are of the correct type).

Ans) D

10. Consider the following:

String message = “Hello”;
message = message + “World”;

What does the second statement do?

a. It adds the characters World to the string object nachrichtreferenced by.
b. It creates a new string object from the original object nachrichtreferenced by, and from another string object containing World .
c. It changes the unchangeable object that is nachrichtreferenced by.
d. It is illegal because it tries to change an immutable object.

Ans) B

 

Java Increment and Decrement Interview Questions

1. Which operation is most often performed by programs?

a. Addition of the integer one to an integer variable.
b. Floating point division.
c. Construction of an object.
d. Access to the Internet.

Ans) A

2. What two steps are performed when an assignment operation is performed?

a.
The expression on the right side of the “=” is evaluated. It uses all the variables it contains.
The result of the evaluation is assigned to the variable on the left side of the “=”.

b.
All suitable variables are incremented or decremented.
The result is assigned to the variable on the left side of the “=”.

c.
All suitable variables are incremented.
All suitable variables are decremented.

d.
The arithmetic expression is evaluated and assigned to the variable on the left side of the “=”.
The variables are automatically incremented or decremented.

Ans) A

3. What does variable ++ mean?

a. Add a one to the variable.
b. Add a one to the variable after its current value is used.
c. Add a one to the variable before using its current value.
d. Double the value of the variable.

Ans) B

4. What will the following program display on the screen:

int number = 0;
int counter = 1;

number = count ++;

System.out.println (“number:” + number “+ count:” + count);

a. number: 0 count: 0
b. number: 0 counter: 1
c. number: 1 count: 1
d. number: 1 counter: 2

Ans) D

5. What will the following program output to the screen:

int number = 0;
int counter = 1;

number = ++ counter; / * Note the difference to the previous program * /

System.out.println (“number:” + number + “counter:” + count);

a. number: 0 counter: 1
b. number: 1 count: 1
c. number: 1 counter: 2
d. number: 2 counter: 2

Ans) D

6. What is the output of the following:

int a = 0;
int b = 10;

a = –b;

System.out.println (“a:” + a + “b:” + b);
a. a: 9b: 11
b. a: 10b: 9
c. a: 9b: 9
d. a: 0b: 9

Ans) C

7. What is the output of the following program:

double w = 12.5;
w * = 2;

System.out.println (“w is” + w);

a. w is 12.5
b. w is 13.5
c. w is 25.0
d. w is 2

Ans) C

 

Java Inheritance Interview Questions

1. What type of inheritance does Java have?

a. single inheritance
b. double inheritance
c. Multiple Inheritance
d. class inheritance

Ans) A

2. Assume that there is three classes Computer, AppleComputerand IBMComputer. What does the relationship between these classes look like?

a. Computeris the superclass, AppleComputerand IBMComputerare subclasses of Computer.
b. IBMComputeris the superclass, AppleComputerand Computerare subclasses of IBMComputer.
c. Computer, AppleComputerand IBMComputerare sibling classes.
d. Computeris a superclass, AppleComputeris a subclass of Computerand IBMComputeris a subclass of AppleComputer.

Ans) A

3. Can an object be the subclass of another object?

a. Yes – as long as the single inheritance is observed.
b. No – inheritance exists only between classes.
c. Only if one is defined in the other’s terms.
d. Yes – when one object is used in the constructor of the other.

Ans) B

4. How many objects of a given class can be in a program?

a. One per defined class.
b. One per constructor definition.
c. As many as the program needs.
d. One per main()method.

Ans) C

5. What restriction is there when using the keyword superin a constructor?

a. It can only be used in the constructor of the superclass.
b. It can only be used by one subclass.
c. It must be used as the last statement of the constructor.
d. It must be used as the first statement of the constructor.

Ans) D

6. A new class GingerAleshould be derived based on the superclass SoftDrink. Which of the following statements is syntactically correct?

a. class GingerAle isa SoftDrink { //more definitions come here }
b. class GingerAle implements SoftDrink { //more definitions come here }
c. class GingerAle defines SoftDrink { //more definitions come here }
d. class GingerAle extends SoftDrink { //more definitions come here }

Ans) D

7. Both the class Autoand its subclass Polohave a method anzeigen()written by the programmer as part of the class definition. If the reference variable rostlauberefers to an object of type Polo, what will the following code do?

rostlaube.anzeigen ();
a. The Show () method, which is Polodefined in, is called.
b. The Show () method, which is Autodefined in, is called.
c. The compiler will complain that has anzeigen()been defined twice.
d. Overload is used to determine which anzeigen()method has been called.

 

Java Abstract Classes Interview Questions

1. What is an abstract class?

a. An abstract class is a class without subclasses.
b. An abstract class is any superclass with more than one subclass.
c. An abstract class is a class that can not be instantiated.
d. An abstract class is another name for a base class.

Ans) C

2. What is an abstract method?

a. An abstract method is any method in an abstract class.
b. An abstract method is a method that can not be inherited.
c. An abstract method is a bodyless method abstractdeclared with the reserved word .
d. An abstract method is a method in the subclass that overrides the method of a superclass.

Ans) C

3. Can an abstract class define both abstract methods and non-abstract methods?

a. No – she must have either one or the other.
b. No – it can only have abstract methods.
c. Yes – but the abstract methods are not inherited from the subclass.
d. Yes – the subclass inherits both.

Ans) D

4. Can an abstract superclass have non-abstract subclasses?

a. No – an abstract superclass may only have abstract subclasses.
b. No – an abstract superclass may not have a subclass at all.
c. Yes, all subclasses of an abstract superclass do not have to be abstract.
d. Yes – an abstract superclass can have both abstract and non-abstract subclasses.

Ans) D

5. Can an abstract method be defined in a non-abstract class?

a. No – if a class defines an abstract method, the class itself must be abstract.
b. No – only classes are abstract, not methods.
c. Yes, a method can be declared abstract in any superclass, as long as it also declares the subclasses to be abstract.
d. Yes – there are no restrictions where abstract methods can be defined.

Ans) A

6. Can an object reference of a subclass be assigned to a variable of the superclass type? For example,

Card card;
Birthday geb = new birthday (“Lucinda”, 42);

card = geb; // is that correct?
a. No – there must always be an exact match between the type of variable and the type of object.
b. No – but an object reference of the superclass type can be assigned to a variable of the subclass type.
c. Yes – an object reference can be assigned to a variable of type superclass.
d. Yes – each object reference can be assigned to each reference variable.

Ans) C

7. What does polymorphism mean in Java?

a. When a single variable is used for several different but related object types in different parts of the program.
b. If a program uses several different types of objects, each with its own variable.
c. If a single superclass has multiple subclasses.
d. If a class has different methods with the same name but different parameter types.

Ans) A

8. What determines in the following which method is executed:

Card card = new birthday (“Lucinda”, 42);

karte.gruss ();
The type of the object or the type of the reference variable?

a. The type of the object.
b. The type of reference variable?

Ans) A

9. For the following code to be correct, what type must the reference variable kartebe?

_________ map;

card = new Valentin (“Joe”, 14);
karte.gruss ();

card = new holiday (“Bob”);
karte.gruss ();

card = new birthday (“Emily”, 12);
karte.gruss ();
a. Valentin
b. holiday
c. birthday
d. map

Ans) D

10. What is the advantage of polymorphism?

a. The same programming logic can be applied to multiple related object types.
b. Variables can be reused to save memory.
c. Constructing new objects from old objects of a similar type saves time.
d. Polymorphism is a dangerous aspect of heredity and should be avoided.

Ans) A

 

Java Polymorphism Interview Questions

1. What is the signature of a method?

a. The signature of a method is the name of a method and the type of its return value.
b. The signature of a method is the name of the method and the names of its parameters.
c. The signature of a method is the name of the method and the data types of its parameters.
d. The signature of a method is the name of the method, its parameter list, and its return type.

Ans) C

2. Here is a method definition:

int compute (int a, double y) {. , , .}
Which of the following definitions has a different signature?

a. int compute (int sum, double value) {. , , .}
b. double compute (int a, double y) {. , , .}
c. double compute (int sum, double y) {. , , .}
d. int compute (int a, int y) {. , , .}

Ans) D

3. What must a non-abstract subclass do with an abstract method of its superclass?

a. A subclass must override an inherited abstract method by defining a method with the same signature and return type:
b. A subclass must define an additional method that is similar to the inherited method in that it defines a method with the same signature but a different return type.)
c. A subclass can not define a method with the same signature as it already has an abstract method of the superclass.
d. A non-abstract subclass can not define an abstract method with the same signature and return type as the superclass’s abstract method.

Ans) A

4. Here is an abstract method defined in the superclass:

public abstract int summiereOuf (int [] arr);
Which of the following methods is required in a non-abstract subclass?

a. public abstract int summiereOuf (int [] arr) {. , , }
b. public int summateOn (int [] arr) {. , , }
c. public double summateOn (int [] arr) {. , , }
d. public int addres (long [] arr) {. , , }

Ans) B

5. What must be true if a subclass of an abstract superclass does not override the abstract methods of the superclass?

a. That’s always a mistake.
b. The subclass itself must be declared abstract.
c. Subclasses are automatically non-abstract, so that’s OK.
d. The superclass is a mistake.

Ans) B

6. Given the following situation:

Happy birthday;
happy = new adult birthday (“Joe”, 39);

happy.gruss ();
Which gruss()method is executed: the one Geburtstagdefined in or the one ErwachsenenGeburtstagdefined in?

a. The one defined in birthday , since that is the type of variable happy.
b. The one ErwachsenenGeburtstagdefined in, because this is the type of happyobject referenced.
c. The one happy.gruss()closest to the instruction in the source code .
d. Neither – the assignment statement is a mistake.

Ans) B

7. Suppose the class Nagerhas a subclass Ratte and another subclass Maus. The class Maushas a subclass TaschenMaus. Check the following:

Rodent rodents;
Rat rat = new rat ();
Mouse mouse = new mouse ();
Pocket mouse pocket mouse = new pocket mouse ();
Which of the following assignments will cause a compile error?

a. rodent = rat;
b. rodent = mouse;
c. pocket mouse = zero;
d. pocket mouse = rat;

Ans) D

8. Assuming the situation is the same as in question 7. Which of the following array declarations is correct for an array that should hold 10 objects of types Ratte, Mausand TaschenMaus?

a. Rat [] array = new rat [10];
b. Rodent [] array = new rat [10];
c. Rodent [] array = new rodent [10];
d. Rodent [10] array;

Ans) C

9. What is the name of the class that is the ancestor of each class in Java?

a. Object
b. Class
c. root
d. Java

Ans) A

10. Check the following code:

String str = “Hot Java”;

boolean flag = str instanceof String;
Which value is transferred flagto?

a. true
b. false
c. “Hot Java”
d. null

Ans) A

 

Java Swing Frames Interview Questions

1. What is called in Java an area on the screen that has nice frames and different buttons below the top frame?

a. window
b. screen
c. box
d. frame

Ans) D

2. What is the name of the swing class used for frames?

a. window
b. frame
c. JFrame
d. Swing frame

Ans) C

3. Which method sets the size of an JFrameobject?

a. setSize( int width, int height)
b. setSize( int height, int width)
c. setVisible( int width, int height)
d. setVisible( int height, int width)

Ans) A

4. The size of a frame on the screen is measured in:

a. inch
b. centimeter
c. points
d. pixel

Ans) D

5. What is a container object in GUI programming?

a. A container is another name for an array or a vector.
b. A container is any class made from another class.
c. A container is a primitive variable containing the current data.
d. A container is an object like a frame that contains other GUI components.

Ans) D

6. Fill in the gaps so that this program displays a JFrame:

import java.awt. *;
import javax.swing. *;

public class microGUI
{
public static void main (String [] args)
{
JFrame frm = new ___________ ();
frm. ___________ (150, 100);
frm. ___________ (true);
}
}

a. Form, setVisible, setOn
b. JFrame, setSize, setVisible
c. Frame, setVisible, setSize
d. Window, setSize, paint

Ans) B

7. Which of the following statements sets a frame to a width of 300 and a height of 200 pixels?

a. frm.setSize( 300, 200 );
b. frm.setSize( 200, 300 );
c. frm.paint( 300, 200 );
d. frm.setVisible( 300, 200 );

Ans) A

 

Java GUI Buttons Interview Questions

1. Which three types of software are needed by a complete GUI program.

A. GUI components, event listeners, application code
For example, action events, widgets, containers
C. Frames, windows, containers
D. Libraries, Toolkits, Interfaces

Ans) A

2. How is a GUI component (like a button) added to a JFrame?

A. insert (component c)
B. add (component c)
C. draw (component c)
D. put (component c)

Ans) B

3. What is the Java software that is intended to be represented like the components of a container?

A. Display Manager
Eg Component Manager
C. Stage Manager
D. Layout Manager

Ans) D

4. Which manager displays components line by line, in the order in which they were added to the frame?

A. Card Layout
B. FlowLayout
C. Grid layout
D. Border Layout

Ans) B

5. Which method of a JFrame is used to select a layout manager?

A. setLayout ()
B. add ()
C. actionPerformed ()
D. setVisible ()

Ans) A

6. Which interface does a class need to implement to become a listener to the ActionEvents of a button?

A. TextListener
B. Runnable
C. ActionListener
D. ImageConsumer

Ans) C

7. Which method does a listener have to implement for Button events?

A. paint ()
Eg windowClosing ()
C. addActionListener ()
D. actionPerformed ()

Ans) D

8. What method of a content pane changes its background color?

A. setBackground (Color c)
B. setForeground (Color c)
C. add ()
D. getBackground ()

Ans) A

9. When should your program repaint()call it?

A. Never – that is the task of the system.
B. Only once when the frame is generated.
C. Whenever a change has been made that leads to a new representation.
D. Whenever a method is ended.

Ans) C

10. Which method will the program end immediately?

A. System.gc ()
Eg System.exit (0)
C. System.setErr ()
D. return ()

Ans) B

 

Java Buttons and Action Events Interview Questions

1. Which method (of a frame) returns a reference to its content area?

A. getContentPane ()
B. contentPane ()
C. framePane ()
D. getPane ()

Ans) A

2. What kind of object determines how GUI components are arranged in a content area?

A. The layer organizer.
B. The Layout Programmer.
C. The layout manager.
D. The Frame Positioner.

Ans) C

3. Which method determines the size of a frame?

A. setSize ()
Eg setDimensions ()
C. showSize ()
D. setRectangle ()

Ans) A

4. Which interface does a button listener have to implement?

A. Action Listener
B. ButtonListener
C. ClickListener
D. DeviceListener

Ans) A

5. Which method does a button listener have to implement?

A. buttonAction ()
Eg eventAction ()
C. actionMethod ()
D. actionPerformed ()

Ans) D

6. What method is used for the content area of ??a frame to set the layout manager?

A. setLayout ()
Eg setLayoutManager ()
C. addLayout
D. setManager ()

Ans) A

7. Which method of the class JButtonsets the command string for a button?

A. setActionCommand (String command)
Eg setCommand (String command)
C. setCommandString (String command)
D. setButtonCommand (String command)

Ans) A

8. Which class of events generate button clicks?

A. ActionEvent
B. ButtonEvent
C. ClickEvent
D. Demo Event

Ans) A

9. Which method determines the command string of an event object?

A. getCommand ()
Eg getActionCommand ()
C. getCommandString ()
D. getButtonText ()

Ans) B

10. How should a command string be compared to a string literal?

A. ==
B. =
C. equals ()
D. equalsIgnoreCase ()

Ans) C

 

Java Labels and Text Fields Interview Questions

1. From which direct base class is JTextFieldderived?

A. JText
B. JField
C. JTextComponent
D. JComponent

Ans) C

2. What must be in the gaps, so that a text field of 20 characters is placed in the frame?

public TextExample ()
{
text = new JTextField ( ____ );
_________ (new FlowLayout ());
add ( ____ );
}

A. text, setLayout, 20
Eg 20, setLayout, text
C. 20, put, frame
D. 20, set, text

Ans) B

3. Which is the class of swing labels?

A. JLabel
Eg label
C. SLable
D. label

Ans) A

4. How to put FlowLayout() components in a frame?

A. It starts at the top, then from left to right for each line.
B. It starts at the bottom, then from right to left for each row.
C. It starts in the middle and then goes spiral outward.
D. He puts the first component in the middle and squeezes the rest around it.

Ans) A

5. When does a text field create an action event?

A. If the field has focus and the Enter key is pressed.
B. For each character entered in the field.
C. Whenever the frame has focus and the Enter key is pressed.
D. When the text box loses focus.

Ans) A

6. Can corrections be made when the user types in a text box?

A. No, every sign will be sent to the application as soon as possible once it has been entered.
B. No, the backspace or delete key ends the entry.
C. Yes, until the Enter key is pressed.
D. Yes, but only deleting the whole line is possible.

Ans) C

7. Which method is used JTextFieldto read the text of one?

A. readText()
B. getText()
C. getString()
D. putText()

Ans) B

8. Can the program put text in JTextField?

A. No, only the user can enter text.
B. Yes, by using one JLabel.
C. Yes, by setEditable()using.
D. Yes, by setText()using.

Ans) D

9. How can the user be prevented from entering text in a text box?

A. By using setEditable( true ).
B. By using setEditable( false ).
C. By using setNotEditable().
D. By using setVisible( false ).

Ans) B

10. Which method changes the background color of a content area?

A. setColor()
B. setBackgroundColor()
C. setBackground()
D. setForegroundColor()

Ans) C

 

Java Components and Layout Interview Questions

1. How can numbers be entered via a graphical interface?

A. The user enters text in a text box. The program must convert the text to a primitive numeric type.
B. The user must press the “Numlock” key on the keyboard so that numbers, not text, are entered.
C. The user enters text in a text box. The text box returns numeric data to the program.
D. If the numbers are not surrounded by quotation marks, they are automatically numeric data.

Ans) A

2. Which type of object determines where to place GUI components in a content area?

A. The layer organizer.
B. The GUI Manager.
C. The layout manager.
D. The Frame Manager.

Ans) C

3. Which is the class for swing labels?

A. JLabel
Eg label
C. SLable
D. label

Ans) A

4. How does FlowLayout()components in the frame?

A. It starts at the top, then from left to right for each line.
B. It starts at the bottom, then from right to left for each row.
C. It starts in the middle and then goes spiral outward.
D. He puts the first component in the middle and squeezes the rest around it.

Ans) A

5. When does a text field create an action event?

A. If the field has focus and the Enter key is pressed.
B. For each character entered in the field.
C. Whenever the frame has focus and the Enter key is pressed.
D. When the text box loses focus.

Ans) A

6. Which interface must a class implement to get an action event listener?

A. TextListener
B. Runnable
C. ActionListener
D. ImageConsumer

Ans) C

7. Which method is used JTextFieldto read text from one ?

A. readText()
B. getText()
C. getString()
D. putText()

Ans) B

8. Which event type does a button click generate?

A. ActionEvent
B. ButtonEvent
C. ClickEvent
D. DoItEvent

Ans) A

9. A graphical user interface contains several components that generate events. What should be done so that the various events can be identified?

A. setEditable( true )Use for each component.
B. setActionCommand() use for each component.
C. Make each component a different type.
D. The listener looks at the values ??in the variables to determine from which component an event comes.

Ans) B

10. If the user changes the size of the frame, what happens to the graphical components?

A. They stay where they are, only the frame gets bigger.
B. The layout manager changes the layout and redistributes the components.
C. The user can not change the size of a frame if the program has been setSizeused.
D. repaint() calls the constructor of the frame, which resets everything back to what it was before.

Ans) B

 

Java Frames Interview Questions

1. What is the part of a frame containing the graphical components?

A. content pane
B. content provider
C. data frame
D. window pane

Ans) A

2. Which type of object determines where the GUI components are placed in a container?

A. The layer organizer.
B. The Component Manager.
C. The Frame Manager.
D. The layout manager.

Ans) D

3. Which method of a frame prevents (or allows) a user to change the size of a frame?

A. setResizable()
B. setStretch()
C. clearSizable()
D. clearUser()

Ans) A

4. How does FlowLayout()the components in a frame?

A. It starts at the top, then from left to right for each line.
B. It starts at the bottom, then from right to left for each row.
C. It starts in the middle and then goes spiral outward.
D. He puts the first component in the middle and squeezes the rest around it.

Ans) A

5. Which type of component is one JPanel()?

A. Container
B. JFrame
C. JButton
D. JWindow

Ans) A

6. What is the default layout manager for JPanel?

A. PanelLayout
B. FrameLayout
C. FlowLayout
D. BoxLayout

Ans) C

7. Which orientation is BoxLayoutpossible?

A. Horizontal only.
B. Horizontal and vertical.
C. Alignment left and right.
D. Centered and justified.

Ans) B

8. Can one be placed JPanelin another JPanel?

A. Yes.
B. No, only visible components can be placed in JPanels.
C. No, JPanelcan not be nested.
D. Yes, but only one JPanelcan be placed in another.

Ans) A

9. Can different layout managers be JPanelchosen for each ?

A. No, only one layout manager can be used for the entire frame.
B. Yes, each container has its own layout manager, independent of the others.
C. No, all JFrames in a frame use the same layout manager.
D. Yes, but only if JPanels are nested.

Ans) B

10. How are components JPaneladded to one?

A. With the set()method.
B. With the add()method.
C. With the put()method.
D. With the setComponent()method.

Ans) B

Related Java 11 Articles

Must Read Java Interview Questions Books 2019

Leave a Reply

Your email address will not be published. Required fields are marked *