The document contains a quiz on Java fundamentals with 29 multiple choice questions covering topics like classes, objects, variables, data types, and methods. It tests understanding of concepts like inheritance, abstraction, polymorphism, and exceptions. The questions have a single correct answer option to select from to test comprehension of Java language rules and behavior.
Oracle Certified Associate (OCA) Java SE 8 Programmer II (1Z0-809) - Practice...Udayan Khattry
Assess your preparation with these Practice Test Questions with Explanation. Questions are Extracted from Highest Rated Course on Udemy which has helped a lot of students to pass the exam with good score.
500+ multiple choice questions with explanation to assess Oracle Certified Associate, Java SE 8 Programmer II preparation.
Highest Rated course on UDEMY
Read the students success stories at:
https://udayankhattry.com/ocp/
Enroll now to receive maximum discount on the course ie. for just $9.99 or ₹640.00, click the link below- https://www.udemy.com/java-ocp/?couponCode=UDAYANKHATTRY.COM
To avail maximum discount on all courses visit: www.udayankhattry.com
In this chapter we will discuss exceptions in the object-oriented programming and in Java in particular. We will learn how to handle exceptions using the try-catch construct, how to pass them to the calling methods and how to throw standard or our own exceptions using the throw construct.
Oracle Certified Associate (OCA) Java SE 8 Programmer II (1Z0-809) - Practice...Udayan Khattry
Assess your preparation with these Practice Test Questions with Explanation. Questions are Extracted from Highest Rated Course on Udemy which has helped a lot of students to pass the exam with good score.
500+ multiple choice questions with explanation to assess Oracle Certified Associate, Java SE 8 Programmer II preparation.
Highest Rated course on UDEMY
Read the students success stories at:
https://udayankhattry.com/ocp/
Enroll now to receive maximum discount on the course ie. for just $9.99 or ₹640.00, click the link below- https://www.udemy.com/java-ocp/?couponCode=UDAYANKHATTRY.COM
To avail maximum discount on all courses visit: www.udayankhattry.com
In this chapter we will discuss exceptions in the object-oriented programming and in Java in particular. We will learn how to handle exceptions using the try-catch construct, how to pass them to the calling methods and how to throw standard or our own exceptions using the throw construct.
SoCal Code Camp 2015: An introduction to Java 8Chaitanya Ganoo
Java 8 introduced cool new features such as Lambdas and Streams. We'll take a look at what they are how to use them effectively. We'll also walkthrough an example of a lightweight Java 8 service running in AWS cloud, which can read and index tweets into an ElasticSearch cluster
In this chapter we will discuss exceptions in the object-oriented programming and in C# in particular. We will learn how to handle exceptions using the try-catch construct, how to pass them to the calling methods and how to throw standard or our own exceptions using the throw construct. We will give various examples for using exceptions. We will look at the types of exceptions and the exceptions hierarchy in the .NET Framework. At the end, we will look at the advantages of using exceptions, best practices and how to apply them in different situations.
TDD, BDD, ATDD are all methodologies that enable incremental design that is suitable for Agile environments. It seems that every day a new xDD methodology is born with the promise to be better than what came before. Should you use behaviour-driven tests or plain old unit tests? Which methodology is better? And how exactly would it benefit the development life cycle?
In this session, Dror will help to sort out the various methodologies – explaining where they came from, the tools they use, and discussing how and when to use each one. Here we will once and for all answer the question as to whether or not there’s one “DD” to rule them all.
Here we are going to learn why is a good practice to use interfaces and how they are different from abstraction classes. Further more we are going to see how which one of them to use.
SoCal Code Camp 2015: An introduction to Java 8Chaitanya Ganoo
Java 8 introduced cool new features such as Lambdas and Streams. We'll take a look at what they are how to use them effectively. We'll also walkthrough an example of a lightweight Java 8 service running in AWS cloud, which can read and index tweets into an ElasticSearch cluster
In this chapter we will discuss exceptions in the object-oriented programming and in C# in particular. We will learn how to handle exceptions using the try-catch construct, how to pass them to the calling methods and how to throw standard or our own exceptions using the throw construct. We will give various examples for using exceptions. We will look at the types of exceptions and the exceptions hierarchy in the .NET Framework. At the end, we will look at the advantages of using exceptions, best practices and how to apply them in different situations.
TDD, BDD, ATDD are all methodologies that enable incremental design that is suitable for Agile environments. It seems that every day a new xDD methodology is born with the promise to be better than what came before. Should you use behaviour-driven tests or plain old unit tests? Which methodology is better? And how exactly would it benefit the development life cycle?
In this session, Dror will help to sort out the various methodologies – explaining where they came from, the tools they use, and discussing how and when to use each one. Here we will once and for all answer the question as to whether or not there’s one “DD” to rule them all.
Here we are going to learn why is a good practice to use interfaces and how they are different from abstraction classes. Further more we are going to see how which one of them to use.
Exam
Name___________________________________
MULTIPLE CHOICE. Choose the one alternative that best completes the statement or answers the question.
1) Analyze the following program fragment:
int x;
double d = 1.5;
switch (d) {
case 1.0: x = 1;
case 1.5: x = 2;
case 2.0: x = 3;
}
1)
A) The switch control variable cannot be double.
B) The program has a compile error because the required break statement is missing in the
switch statement.
C) The program has a compile error because the required default case is missing in the switch
statement.
D) No errors.
2) Analyze the following code:
boolean even = false;
if (even = true) {
System.out.println("It is even!");
}
2)
A) The program runs fine, but displays nothing.
B) The program runs fine and displays It is even!.
C) The program has a runtime error.
D) The program has a compile error.
3) What is the printout of the following switch statement?
char ch = 'a';
switch (ch) {
case 'a':
case 'A':
System.out.print(ch); break;
case 'b':
case 'B':
System.out.print(ch); break;
case 'c':
case 'C':
System.out.print(ch); break;
case 'd':
case 'D':
System.out.print(ch);
}
3)
A) abc B) abcd C) ab D) aa E) a
1
4) The order of the precedence (from high to low) of the operators +, *, &&, ||, & is: 4)
A) *, +, &, &&, ||
B) *, +, &&, ||, &
C) &&, ||, &, *, +
D) &, ||, &&, *, +
E) *, +, &, ||, &&
5) The statement System.out.printf("%10s", 123456) outputs ________. (Note: * represents a space) 5)
A) ****123456 B) 12345***** C) 123456**** D) 23456*****
6) The following code displays ________.
double temperature = 50;
if (temperature >= 100)
System.out.println("too hot");
else if (temperature <= 40)
System.out.println("too cold");
else
System.out.println("just right");
6)
A) too cold B) too hot
C) too hot too cold just right D) just right
7) Which of the following code displays the area of a circle if the radius is positive? 7)
A) if (radius >= 0) System.out.println(radius * radius * 3.14159);
B) if (radius != 0) System.out.println(radius * radius * 3.14159);
C) if (radius > 0) System.out.println(radius * radius * 3.14159);
D) if (radius <= 0) System.out.println(radius * radius * 3.14159);
8) ________ is the code with natural language mixed with Java code. 8)
A) A flowchart diagram B) Java program
C) Pseudocode D) A Java statement
9) Analyze the following code:
if (x < 100) && (x > 10)
System.out.println("x is between 10 and 100");
9)
A) The statement compiles fine.
B) The statement has compile errors because (x<100) & (x > 10) must be enclosed inside
parentheses and the println(…) statement must be put inside a block.
C) The statement compiles fine, but has a runtime error.
D) The statement has compile errors because (x<100) & (x > 10) must be enclosed inside
parentheses.
10) In Java, the word true is ________. 10)
A) same as value 1 B) same as value 0
C) a Boolean literal D) a Java keyword
2
11) How many time ...
Q3 GIVEN THE TREND EQUATION NO OF STUDENTS-3000+200 YEAR BASE: 2003-0
1.INTERPRET EQUATION RESULTS 2.FORECAST FOR 2020 3.WHEN WILL THE NO OF
STUDENTS REACH 6000
Solution
x no of years from 2003 y no of students y = 3000+200x 1) The regression
equation has a positive slope of 200 y intercept is 3000 i.e. no of students in the year 2000
Thus for every year 200 students increase 2) For 2020, x = 17, y = 3000+200(17) = 6400
3) When y =6000, 6000 = 3000+200x or x = 15 Hence in year 2018 students reach 6000
B Regression C D. All the above.
All based on Zybooks = AP Java with zylabsQUESTION 1char[][] tab.pdfaroraenterprisesmbd
All based on Zybooks = AP Java with zylabs
QUESTION 1
char[][] table = new char[10][5];
How many rows are in the array seen in the accompanying figure?
0
5
10
15
QUESTION 2
The standard output object in Java is ____.
output
System.out
Sys.out
System.in
QUESTION 3
The length of the string \"first java program\" is:
16
18
19
20
1 points
QUESTION 4
The loop condition of a while loop is reevaluated before every iteration of the loop.
True
False
1 points
QUESTION 5
If str1 is “Hello” and str2 is “Hi”, which of the following could not be a result of
str1.compareTo(str2);?
-9
-5
-1
1
1 points
QUESTION 6
Both System.out.println and System.out.print can be used to output a string on the standard
output device.
True
False
1 points
QUESTION 7
In a method call statement, when passing an array as an actual parameter, you use only its name.
True
False
1 points
QUESTION 8
Which of the following is true about a while loop?
The body of the loop is executed at least once.
The logical expression controlling the loop is evaluated before the loop is entered and after the
loop exists.
The body of the loop may not execute at all.
It is a post-test loop
1 points
QUESTION 9
int x, y;
if (x < 4)
y = 2;
else if (x > 4)
{
if (x > 7)
y = 4;
else
y = 6;
}
else
y = 8;
Based on the code above, what is the value of y if x = 9?
2
4
6
8
1 points
QUESTION 10
The array index can be any nonnegative integer less than the array size.
True
False
1 points
QUESTION 11
When a program executes, the first statement to execute is always the first statement in the main
method.
True
False
1 points
QUESTION 12
Java stores two-dimensional arrays in a row order form in computer memory.
True
False
1 points
QUESTION 13
The statement dataType[][][] arrayName; would declare a two-dimensional array.
True
False
1 points
QUESTION 14
All the methods defined in a class must have different names.
True
False
1 points
QUESTION 15
Which of the following is NOT a reserved word in Java?
double
throws
static
num
1 points
QUESTION 16
Given the declaration
int[] list = new int[50];
the statement
System.out.println(list[0] + \"...\" + list[49]);
outputs all 50 components of the array list.
True
False
1 points
QUESTION 17
In the case of an infinite while loop, the while expression (that is, the loop condition) is always
true.
True
False
1 points
QUESTION 18
Consider the following program.
public class CircleArea
{
static Scanner console = new Scanner(System.in);
static final double PI = 3.14;
public static void main(String[]args)
{
doubler;
double area;
r = console.nextDouble();
area = PI * r * r;
System.out.println(\"Area = \" + area);
}
}
To successfully compile this program, which of the following import statement is required?
import java.io.Scanner;
import java.util.Scanner;
import java.lang.Scanner;
No import statement is required
1 points
QUESTION 19
An identifier can be any sequence of characters and integers.
True
False
1 points
QUESTION 20
A single array can hold elements of many different data types.
Tr.
Name _______________________________ Class time __________.docxrosemarybdodson23141
Name: _______________________________ Class time: __________
Prewriting Instructions for Paper 2 (Final Paper due 4/22)
1. Your choices for Paper 2 are posted on blackboard and also listed below.
2. Choose 1 of these paper options. Notice that each choice also mentions the type of paper (comparison, etc.) My paper choice is: _________________________: paper type: _______________.
3. Read the related essay(s) in your Research and Composition textbook.
4. Thursday: write a tentative thesis for paper 2 (one sentence): ______________________________________________________________________________________________________________________________________________________________________________________________________________________.
5. Thursday: write 5 questions that you will need to answer through research to write this paper (for ex. What is the divorce rate for 2012?) Write legibly please.
1.
2.
3.
4.
5.
6. Thursday: go to the library and use the databases to locate at least three sources that will likely give you the information to answer the five questions above. At least one should be a book, at least one should be a database article. In addition, you may use your textbook, internet, or even refer to a film. Write down the all of the information about each source. You will need this information for a works cited page later or to locate the article and book again. You do not need to answer the questions right away, but if you do find the answers, take notes or make a copy of the source.
Source 1: ____________________________________________________________________________________________________________________________________________________________
Source 2: ____________________________________________________________________________________________________________________________________________________________
Source 3: ____________________________________________________________________________________________________________________________________________________________
7. Have any new questions come to mind? What are they? Write them here:
8. Have you revised your thesis? What is it? ___________________________________
_____________________________________________________________________.
9. Write a tentative first paragraph to paper 2 (this includes your thesis):
10. Turn this in Tuesday 3/25 in exchange for your last Q exercise, M&M Color Distribution.
***You need this prewriting exercise completed to receive your instructions and data for this last Q exercise and parts of this exercise will count for your attendance in a week or so.
See next page
Writing Assignment 2 Choices due on or before 4/22
Here are your choices for Writing Assignment 2 due 4/22. Additional research is required for all choices. Two visuals, tables or figures, are required. Your paper will be in MLA format with a works cited page. This paper is approximately 5 pages including a works cited page.
1. Read the essays in Chapter 8. Go .
1z0 851 exam-java standard edition 6 programmer certified professionalIsabella789
Guaranteed success with updated troytec dumps for 1Z0-851 Exam-Java Standard Edition 6 Programmer Certified Professional visit@ https://www.troytec.com/1Z0-851-exams.html
Question 1 1 pts Skip to question text.As part of a bank account.docxamrit47
Question 1 1 pts Skip to question text.
As part of a bank account implementation, there is an account class and a checking account class. These two classes should be related by:
polymorphism
abstract classes
both composition and inheritance
inheritance
composition
Flag this Question
Question 2 1 pts
When using OOP, which of the following terms refers to a mechanism for a behavior, basically how it’s implemented?
composition
inheritance
polymorphism
dynamic binding
Flag this Question
Question 3 1 pts
To access an element in an Array object,
Use the ArrayList's get() method.
Use the ArrayList's element() method.
Individual elements in an ArrayList can’t be accessed without doing a sequential query getSequential(), returning every element up to and including the element requested.
Use square brackets around an index value.
Flag this Question
Question 4 1 pts
To access an element in an ArrayList object,
Use square brackets around an index value.
Use the ArrayList element() method.
Use the ArrayList get() method.
Individual elements in an ArrayList can’t be accessed without doing a sequential query getSequential(), returning every element up to and including the element requested.
Flag this Question
Question 5 1 pts
What term below is defined as a message that tells the program that something has happened?
an interaction
a listener
an action
an event
Flag this Question
Question 6 1 pts
Which item below is defined as an object?
A String
An Array
All of the above
An ArrayList
Flag this Question
Question 7 1 pts
When a text-box-enter event occurs, which method and parameter are required to handle this type of action? (1 point)
actionEvent with an actionperformed parameter
actionListener with an interfaceID parameter
windowListener with an eventID parameter
actionPerformed with an actionEvent parameter
Flag this Question
Question 8 1 pts
Which class includes the setTitle and setSize methods?
JFrame
JWindow
JBox
JOptionpane
Flag this Question
Question 9 1 pts
Before utilizing the binary search method, __________ must be done to the array?
indexing
splitting
sorting
importing
Flag this Question
Question 10 1 pts
Which layout manager implements a one-compartment layout scheme?
GridlessLayout
GridBagLayout
GridLayout
FlowLayout
BorderLayout
Flag this Question
Question 11 1 pts
What is the default layout manager for a JFrame window?
GridBagLayout
GridLayout
FlowLayout
GridlessLayout
BorderLayout
Flag this Question
Question 12 1 pts
To call the superclass constructor, super() must be the first line in a constructor.
True
False
Flag this Question
Question 13 1 pts
Method overriding is when a method has the same name, same sequence of parameter types, and the same return type as a method in a superclass.
True
False
Flag this Question
Question 14 1 pts
Type casting, also known as promotion is ...
Read| The latest issue of The Challenger is here! We are thrilled to announce that our school paper has qualified for the NATIONAL SCHOOLS PRESS CONFERENCE (NSPC) 2024. Thank you for your unwavering support and trust. Dive into the stories that made us stand out!
2024.06.01 Introducing a competency framework for languag learning materials ...Sandy Millin
http://sandymillin.wordpress.com/iateflwebinar2024
Published classroom materials form the basis of syllabuses, drive teacher professional development, and have a potentially huge influence on learners, teachers and education systems. All teachers also create their own materials, whether a few sentences on a blackboard, a highly-structured fully-realised online course, or anything in between. Despite this, the knowledge and skills needed to create effective language learning materials are rarely part of teacher training, and are mostly learnt by trial and error.
Knowledge and skills frameworks, generally called competency frameworks, for ELT teachers, trainers and managers have existed for a few years now. However, until I created one for my MA dissertation, there wasn’t one drawing together what we need to know and do to be able to effectively produce language learning materials.
This webinar will introduce you to my framework, highlighting the key competencies I identified from my research. It will also show how anybody involved in language teaching (any language, not just English!), teacher training, managing schools or developing language learning materials can benefit from using the framework.
Operation “Blue Star” is the only event in the history of Independent India where the state went into war with its own people. Even after about 40 years it is not clear if it was culmination of states anger over people of the region, a political game of power or start of dictatorial chapter in the democratic setup.
The people of Punjab felt alienated from main stream due to denial of their just demands during a long democratic struggle since independence. As it happen all over the word, it led to militant struggle with great loss of lives of military, police and civilian personnel. Killing of Indira Gandhi and massacre of innocent Sikhs in Delhi and other India cities was also associated with this movement.
How to Make a Field invisible in Odoo 17Celine George
It is possible to hide or invisible some fields in odoo. Commonly using “invisible” attribute in the field definition to invisible the fields. This slide will show how to make a field invisible in odoo 17.
How to Create Map Views in the Odoo 17 ERPCeline George
The map views are useful for providing a geographical representation of data. They allow users to visualize and analyze the data in a more intuitive manner.
Ethnobotany and Ethnopharmacology:
Ethnobotany in herbal drug evaluation,
Impact of Ethnobotany in traditional medicine,
New development in herbals,
Bio-prospecting tools for drug discovery,
Role of Ethnopharmacology in drug evaluation,
Reverse Pharmacology.
Unit 8 - Information and Communication Technology (Paper I).pdfThiyagu K
This slides describes the basic concepts of ICT, basics of Email, Emerging Technology and Digital Initiatives in Education. This presentations aligns with the UGC Paper I syllabus.
2. Question 1
An object is
Select 1 correct option.
a what classes are instantiated from.
b an instance of a class.
c a blueprint for creating concrete realization of abstractions.
d a reference to an attribute.
e a variable.
Ans: b
3. Question 2
What will the following code snippet print?
int index = 1;
String[] strArr = new String[5];
String myStr = strArr[index];
System.out.println(myStr);
Select 1 correct option.
A It will print nothing.
B It will print 'null'
C It will throw ArrayIndexOutOfBounds at runtime.
D It will print NullPointerException at runtime.
E None of the above.
Ans: b
4. Question 3
In which of these variable declarations, will the variable remain uninitialized
unless explicitly initialized?
Select 1 correct option.
a Declaration of an instance variable of type int.
b Declaration of a static class variable of type float.
c Declaration of a local variable of type float.
d Declaration of a static class variable of class Object
e Declaration of an instance variable of class Object.
Ans: c
5. Question 4
What is the range of a 'char' data type?
Select 1 correct option.
a 0 - 65, 535
b 0 - 65, 536
c -32,768 - 32,767
d 0 - 32,767
e None of the above
Ans: a
6. Question 5
What will the following program print?
public class TestClass
{
public static void main(String[] args)
{
unsigned byte b = 0;
b--;
System.out.println(b);
}
}
Select 1 correct option.
A0
B -1
C 255
D -128
E It will not compile.
Ans: e unsigned
7. Question 6
Carefully examine the following code.
public class StaticTest
{
static
{ System.out.println("In static"); }
{ System.out.println("In non - static"); }
public static void main(String args[ ])
{
StaticTest st1; //1
System.out.println(" 1 ");
st1 = new StaticTest(); //2
System.out.println(" 2 ");
StaticTest st2 = new StaticTest(); //3
}
}
What will be the output?
Select 1 correct option.
a In static, 1, In non - static, 2, In non - static : in that order.
b Compilation error.
c 1, In static, In non - static, 2, In non - static : in that order.
d In static, 1, In non - static, 2, In non - static : in unknown order.
e None of the above.
Ans: a
8. Question 7
What will happen when you compile and run the following program using the
command line:
java TestClass 1 2
public class TestClass
{
public static void main(String[] args)
{
int i = Integer.parseInt(args[1]);
System.out.println(args[i]);
}
}
Select 1 correct option.
a It'll print 1
b It'll print 2
c It'll print some junk value.
d It'll throw ArrayIndexOutOfBoundsException
e It'll throw NumberFormatException
Ans: d
9. Question 8
Which of the following are valid at line 1?
public class X
{
line 1: //put statement here.
}
Select 2 correct options
a String s;
b String s = 'asdf';
c String s = 'a';
d String s = this.toString();
e String s = asdf;
Ans: a&d
10. Question 9
A method is ..
Select 1 correct option.
a an implementation of an abstraction.
b an attribute defining the property of a particular abstraction.
c a category of objects.
d an operation defining the behavior for a particular abstraction.
e a blueprint for making operations.
Ans: d
11. Question 10
An instance member ...
Select 2 correct options
a can be a variable, constant or a method.
b is a variable or a constant.
c Belongs to the class.
d Belongs to an instance of the class.
e is same as a local variable.
Ans: a&d
12. Question 11
Given the following class, which of these given blocks can be inserted at line
1 without errors?
public class InitClass
{
private static int loop = 15 ;
static final int INTERVAL = 10 ;
boolean flag ;
//line 1
}
Select 4 correct options
a static {System.out.println("Static"); }
b static { loop = 1; }
c static { loop += INTERVAL; }
d static { INTERVAL = 10; }
e { flag = true; loop = 0; }
Ans: a,b,c,e
13. Question 12
Which of the following are correct ways to initialize the static variables MAX and CLASS_GUID ?
class Widget
{
static int MAX; //1
static final String CLASS_GUID; // 2
Widget()
{
//3
}
Widget(int k)
{
//4
}
}
Select 2 correct options
a Modify lines //1 and //2 as : static int MAX = 111; static final String CLASS_GUID = "XYZ123";
b Add the following line just after //2 : static { MAX = 111; CLASS_GUID = "XYZ123"; }
c Add the following line just before //1 : { MAX = 111; CLASS_GUID = "XYZ123"; }
d Add the following line at //3 as well as //4 : MAX = 111; CLASS_GUID = "XYZ123";
e Only option 3 is valid.
Ans: a,b
14. Question 13
What will be the result of attempting to compile and run the following class?
public class TestClass
{
public static void main(String args[ ] )
{
int i = 1;
int[] iArr = {1};
incr(i) ;
incr(iArr) ;
System.out.println( "i = " + i + " iArr[0] = " + iArr [ 0 ] ) ;
}
public static void incr(int n ) { n++ ; }
public static void incr(int[ ] n ) { n [ 0 ]++ ; }
}
Select 1 correct option.
a The code will print i = 1 iArr[0] = 1;
b The code will print i = 1 iArr[0] = 2;
c The code will print i = 2 iArr[0] = 1;
d The code will print i = 2 iArr[0] = 2;
e The code will not compile.
Ans: b
15. Question 14
Consider the following code snippet ...
boolean[] b1 = new boolean[2];
boolean[] b2 = {true , false};
System.out.println( "" + (b1[0] == b2[0]) + ", "+ (b1[1] == b2[1]) );
What will it print ?
Select 1 correct option.
a It will not compile.
b It will throw ArrayIndexOutOfBoundsError at Runtime.
c It will print false, true.
d It will print true, false.
e It will print false, false.
Ans: c
16. Question 15
What will the following program print?
public class TestClass
{
static String str;
public static void main(String[] args)
{
System.out.println(str);
}
}
Select 1 correct option.
a It will not compile.
b It will compile but throw an exception at runtime.
c It will print 'null'
d It will print nothing.
e None of the above.
Ans: c
17. Question 16
public class TestClass
{
public static void main(String[] args)
{
String tom = args[0];
String dick = args[1];
String harry = args[2];
}
}
What will the value of 'harry' if the program is run from the command
line:
java TestClass 111 222 333
Select 1 correct option.
a 111
b 222
c 333
d It will throw an ArrayIndexOutOfBoundsException
e None of the above.
Ans: c
18. Question 17
Which of these are keywords in Java?
Select 3 correct options
a default
b NULL
c String
d throws
e long
Ans: a,d,e
19. Question 18
Which of the following are valid identifiers?
Select 2 correct options
a class
b $value$
c angstrom
d 2much
e zer@
Ans: b,c
20. Question 19
public class TestClass
{
public static void main(String[] args)
{
String str = "111";
boolean[] bA = new boolean[1];
if( bA[0] ) str = "222";
System.out.println(str);
}
}
What will the above program print?
Select 1 correct option.
a 111
b 222
c It will not compile as bA[0] is uninitialized.
d It will throw an exception at runtime.
e None of the above.
Ans: a
21. Question 20
What will be the output of the following lines ?
System.out.println("" +5 + 6); //1
System.out.println(5 + "" +6); // 2
System.out.println(5 + 6 +""); // 3
System.out.println(5 + 6); // 4
Select 1 correct option.
a 56, 56, 11, 11
b 11, 56, 11, 11
c 56, 56, 56, 11
d 56, 56, 56, 56
e 56, 56, 11, 56
Ans: a
22. Question 21
Which of the following is not a primitive data value in Java?
Select 2 correct options
a "x"
b 'x'
c 10.2F
d Object
e false
Ans: a,d
23. Question 22
What does the zeroth element of the string array passed to the standard main
method contain?
Select 1 correct option.
a The name of the class.
b The string "java".
c The number of arguments.
d The first argument of the argument list, if present.
e None of the above.
Ans: d
24. Question 23
What will the following program print?
public class TestClass
{
static boolean b;
static int[] ia = new int[1];
static char ch;
static boolean[] ba = new boolean[1];
public static void main(String args[]) throws Exception
{
boolean x = false;
if( b )
{
x = ( ch == ia[ch]);
}
else x = ( ba[ch] = b );
System.out.println(x+" "+ba[ch]);
}
}
Select 1 correct option.
a true true
b true false
c false true
d false false
e It'll not compile.
Ans: d
25. Question 24
What will be the result of attempting to compile and run the following code?
public class InitClass
{
public static void main(String args[ ] )
{
InitClass obj = new InitClass(5);
}
int m;
static int i1 = 5;
static int i2 ;
int j = 100;
int x;
public InitClass(int m)
{
System.out.println(i1 + " " + i2 + " " + x + " " + j + " " + m);
}
{ j = 30; i2 = 40; } // Instance Initializer
static { i1++; } // Static Initializer
}
Select 1 correct option.
a The code will fail to compile, since the instance initializer tries to assign a value to a static member.
b The code will fail to compile, since the member variable x will be uninitialized when it is used.
c The code will compile without error and will print 6, 40, 0, 30, 5 when run.
d The code will compile without error and will print 5, 0, 0, 100, 5 when run.
e The code will compile without error and will print 5, 40, 0, 30, 0 when run.
Ans: c
26. Question 25
Which code fragments will print the last argument given on the command line to the standard output, and exit without any output and
exceptions if no arguments are given?
1.
public static void main(String args[ ])
{
if (args.length != 0) System.out.println(args[args.length-1]);
}
2.
public static void main(String args[ ])
{
try { System.out.println(args[args.length-1]); }
catch (ArrayIndexOutOfBoundsException e) { }
}
3.
public static void main(String args[ ])
{
int i = args.length;
if (i != 0) System.out.println(args[i-1]);
}
4.
public static void main(String args[ ])
{
int i = args.length-1;
if (i > 0) System.out.println(args[i]);
}
5.
public static void main(String args[ ])
{
try { System.out.println(args[args.length-1]); }
catch (NullPointerException e) {}
}
Select 3 correct options
a Code No. 1
b Code No. 2
c Code No. 3
d Code No. 4
e Code No. 5
Ans: a,b,c
27. Question 26
Consider the following class:
public class ArgsPrinter
{
public static void main(String args)
{
for(int i=0; i<3; i++)
{
System.out.println(args);
}
}
}
What will be printed when the above class is run using the following command line:
java ArgsPrinter 1 2 3 4
Select 1 correct option.
a123
b ArgsPrinter 1 2
c java ArgsPrinter 1 2
d111
e None of these.
Ans: e
28. Question 27
Consider the following class definition:
public class TestClass
{
public static void main(){ new TestClass().sayHello(); } //1
public static void sayHello(){ System.out.println("Static Hello World"); } //2
public void sayHello() { System.out.println("Hello World "); } //3
}
What will be the result of compiling and running the class?
Select 1 correct option.
a It will print 'Hello World'.
b It will print 'Static Hello World'.
c Compilation error at line 2.
d Compilation error at line 3.
e Runtime Error.
Ans: b
29. Question 28
What will the following program print?
public class TestClass
{
static int someInt = 10;
public static void changeIt(int a)
{
a = 20;
}
public static void main(String[] args)
{
changeIt(someInt);
System.out.println(someInt);
}
}
Select 1 correct option.
a 10
b 20
c It will not compile.
d It will throw an exception at runtime.
e None of the above.
Ans: a
30. Question 29
What is the numerical range of short data type?
Select 1 correct option.
a It depends on the platform the JVM is running.
b 0 to 65535
c -32768 to 32767
d 0 to 32767
e -16384 to 16383
Ans: c