SlideShare a Scribd company logo
Question 1
How many parameters does a default constructor have?
Ans) It never has any
Explanation:
The default constructor doesn’t have any parameters.Thats why it is also called as Zero-
Argumented constructor.
Even The default constructor doesn’t return anything even void also.
___________________________________________________________________
Question 2
Which of the following statements is true about the class shown below?
class Quiz1A
{
private int[] array = new int[10];
public int[] getArray()
{
return array;
}
}
Ans) It is immutable
Explanation:
Here the getArray() method is not doing any operations inside it.It just returning an array.So it is
also called as getter method.
______________________________________________________________________
Question 3
A method that is associated with an individual object is called __________.
Ans) an instance method
Explanation:
For every class we can create many objects.If we want to call a method on object, we have to call
a method by using the reference of it.That method is confined to that object only.
______________________________________________________________________
Question 4
Given the declaration Circle[] x = new Circle[10], which of the following statement is most
accurate?
Ans) x contains a reference to an array and each element in the array can hold a reference to a
Circle object.
Explanation:
This array will hold the references of Circle class objects.It will not store objects.
______________________________________________________________________
Question 5
What is the output of the program shown below?
public class Quiz1B
{
public static void main(String[] args)
{
Count count = new Count();
int times = 0;
for (int i = 0; i < 100; i++)
increment(count, times);
System.out.println("times = " + times + " count = " + count.times);
}
public static void increment(Count count, int times)
{
count.times++;
times++;
}
}
class Count
{
int times;
public Count()
{
times = 1;
}
}
Ans) times = 100 count = 101
Explanation:
This for loop in the main method will be executed for 100 times.So the value of the variable of
main method times will increased by 1 for each iteration.As the initial value of times is 0 and
finally it will become 100.after 100 iterations
As the initial value of instance variable of Count class is 1.After 100 iterations its value will
become 101
______________________________________________________________________
Question 6
When calling a method with an object argument, ___________ is passed.
Ans) the reference of the object
Explanation:
We have to pass the reference of an object as argument while calling.not the copy or objects
contents or else.
______________________________________________________________________
Question 7
Which of the following is not a property of a constructor?
Ans) The name of a constructor can be chosen by the programmer
Explanation:
We can overload the constructor.
The constructor is called and executed when we are creating an object by using new operator.
The name of the constructor should be the name of the class.We cannot choose the name of the
constructor.
______________________________________________________________________
Question 8
What is the output of the program shown below?
public class Quiz1C
{
public static void main(String[] args)
{
int i = 1;
StringBuilder s = new StringBuilder("s");
String t = "t";
someMethod(i, s, t);
System.out.print("i = " + i + ", ");
System.out.print("s = " + s + ", ");
System.out.println("t = " + t);
}
private static void someMethod(int i, StringBuilder s, String t)
{
i++;
s.append("s");
t += "t";
}
}
Ans) i = 2, s = ss, t = tt
Explanation:
We are calling the method someMethod(int i, StringBuilder s, String t) by passing the int
variable,references of StringBuilder and String
Inside that i value will be incremented by 1
Appending s to the content of StringBuilder Object.
Concatenating t to the String “t”
______________________________________________________________________
Question 9
Which of the following statements is true about the order of methods in a class.
Ans) They can be listed in any order
Explanation:
We can declare the methods inside the class in any order .there is no restrictions on the order of
declaration of methods.
______________________________________________________________________
Question 10
Which of the following statements about constructors is true?
Ans) A default constructor is provided automatically if no constructors are explicitly declared in
the class
Explanation:
If we didnt provided any constructor in a class,the java compiler will provide the code for default
constructor inside the class while compiling the class.
______________________________________________________________________
Question 11
Which of the following is true about the program shown below?
class Quiz1D
{
private int x;
public Quiz1D(int x)
{
this.x = x;
}
}
Ans) If the this qualifier is removed, it will compile but won't initialize the instance variable
Explanation:
This refers to the current class instance variable.Even If we didn’t provide ‘this’ also our
program will compile but the instance variable will not get initialized.So the instance variable
will be initialized with the default value.
______________________________________________________________________
Question 12
Which of the following statements about local variables is true?
Ans) A compilation error results when a local variable is accessed before it is initialized.
Explanation:
Even if we didn’t initialize the during compilation instance variables will be initialized with their
default values.
But if we want to use local variables compulsory we have to initialize it.If not we will get
compilation error.
______________________________________________________________________
Question 13
Analyze the code shown below and indicate which of the following is true:
class Quiz1E
{
private double variable;
public Quiz1E(double variable)
{
variable = variable;
}
}
Ans)
The program will compile, but you cannot create an object of Quiz1E with a specified value for
variable
Explanation:
As we didn’t provide ‘this’ so the variable will not get initialized.
We wont get any compilation error.But the instance variable value of Quiz1E class will be
initialized with the default values by the java compiler.So as it is double data type it will be
initialized with 0.0
______________________________________________________________________
Question 14
Which of the following is true of public methods?
Ans) They can only be accessed by methods in a different package
Explanation:
The scope of the public access specifier is global.So we can access public methods from
anywhere like with in the class or from with in the package or from outside the package.
______________________________________________________________________
Question 15
Which of the following statements is true about an immutable object?
Ans) The contents of an immutable object cannot be modified
Explanation:
Immutable:
the state or contents of an object cannot be changed or modified.best example for this is String
class .We cannot change the contents of the String class Object contents.
______________________________________________________________________
Question 16
What is the output of the program shown below?
public class Quiz1F
{
private static int i = 0;
public static void main(String[] args)
{
{
int i = 3;
}
System.out.println("i is " + i);
}
}
Ans) i is 0
Explanation:
The scope of the local variable is confined only to the method itself in which it has been
declared.
So if we print ‘i’ 0 will be displayed as output.which is the value of the static variable i.as we
declared private static int i = 0;
______________________________________________________________________
Question 17
Which of the following statements is true of the reserved word this?
Ans) It can be only used in instance methods and constructors
Explanation:
This refer to the current class instance variables.We can use ‘this’ to initialize the instance
variables.
______________________________________________________________________
Question 18
Which of the following statements is true about the class shown below?
public class Quiz1G
{
private void method()
{
}
public static void main(String[] args)
{
method();
}
}
Ans) It won't compile because method needs to be static
Explanation:
First the program wont compile.because we didn’t declare that method as static.To solve the
error we have to declare the method as static.
privatestaticvoid method()
{
System.out.println("x");
}
______________________________________________________________________
Question 19
Which of the following statements is true of private instance variables?
Ans) They can accessed in any instance method in the same class
Explanation:
The scope of the private is confined to the class itself.We can access the private variables only
with in the class in which they have been declared.We can access private instance variables in
any method of the same class.
______________________________________________________________________
Question 20
Which of the following statements about class (static) variables is correct?
Ans) There is only one copy of each class variable that is shared by all instances of the class
Explanation:
Static variable:Only one copy of static variable is shared by all the instances of the class.if we
modified the value of static variable in one object then it will reflects in other objects of the same
class also.
______________________________________________________________
Solution
Question 1
How many parameters does a default constructor have?
Ans) It never has any
Explanation:
The default constructor doesn’t have any parameters.Thats why it is also called as Zero-
Argumented constructor.
Even The default constructor doesn’t return anything even void also.
___________________________________________________________________
Question 2
Which of the following statements is true about the class shown below?
class Quiz1A
{
private int[] array = new int[10];
public int[] getArray()
{
return array;
}
}
Ans) It is immutable
Explanation:
Here the getArray() method is not doing any operations inside it.It just returning an array.So it is
also called as getter method.
______________________________________________________________________
Question 3
A method that is associated with an individual object is called __________.
Ans) an instance method
Explanation:
For every class we can create many objects.If we want to call a method on object, we have to call
a method by using the reference of it.That method is confined to that object only.
______________________________________________________________________
Question 4
Given the declaration Circle[] x = new Circle[10], which of the following statement is most
accurate?
Ans) x contains a reference to an array and each element in the array can hold a reference to a
Circle object.
Explanation:
This array will hold the references of Circle class objects.It will not store objects.
______________________________________________________________________
Question 5
What is the output of the program shown below?
public class Quiz1B
{
public static void main(String[] args)
{
Count count = new Count();
int times = 0;
for (int i = 0; i < 100; i++)
increment(count, times);
System.out.println("times = " + times + " count = " + count.times);
}
public static void increment(Count count, int times)
{
count.times++;
times++;
}
}
class Count
{
int times;
public Count()
{
times = 1;
}
}
Ans) times = 100 count = 101
Explanation:
This for loop in the main method will be executed for 100 times.So the value of the variable of
main method times will increased by 1 for each iteration.As the initial value of times is 0 and
finally it will become 100.after 100 iterations
As the initial value of instance variable of Count class is 1.After 100 iterations its value will
become 101
______________________________________________________________________
Question 6
When calling a method with an object argument, ___________ is passed.
Ans) the reference of the object
Explanation:
We have to pass the reference of an object as argument while calling.not the copy or objects
contents or else.
______________________________________________________________________
Question 7
Which of the following is not a property of a constructor?
Ans) The name of a constructor can be chosen by the programmer
Explanation:
We can overload the constructor.
The constructor is called and executed when we are creating an object by using new operator.
The name of the constructor should be the name of the class.We cannot choose the name of the
constructor.
______________________________________________________________________
Question 8
What is the output of the program shown below?
public class Quiz1C
{
public static void main(String[] args)
{
int i = 1;
StringBuilder s = new StringBuilder("s");
String t = "t";
someMethod(i, s, t);
System.out.print("i = " + i + ", ");
System.out.print("s = " + s + ", ");
System.out.println("t = " + t);
}
private static void someMethod(int i, StringBuilder s, String t)
{
i++;
s.append("s");
t += "t";
}
}
Ans) i = 2, s = ss, t = tt
Explanation:
We are calling the method someMethod(int i, StringBuilder s, String t) by passing the int
variable,references of StringBuilder and String
Inside that i value will be incremented by 1
Appending s to the content of StringBuilder Object.
Concatenating t to the String “t”
______________________________________________________________________
Question 9
Which of the following statements is true about the order of methods in a class.
Ans) They can be listed in any order
Explanation:
We can declare the methods inside the class in any order .there is no restrictions on the order of
declaration of methods.
______________________________________________________________________
Question 10
Which of the following statements about constructors is true?
Ans) A default constructor is provided automatically if no constructors are explicitly declared in
the class
Explanation:
If we didnt provided any constructor in a class,the java compiler will provide the code for default
constructor inside the class while compiling the class.
______________________________________________________________________
Question 11
Which of the following is true about the program shown below?
class Quiz1D
{
private int x;
public Quiz1D(int x)
{
this.x = x;
}
}
Ans) If the this qualifier is removed, it will compile but won't initialize the instance variable
Explanation:
This refers to the current class instance variable.Even If we didn’t provide ‘this’ also our
program will compile but the instance variable will not get initialized.So the instance variable
will be initialized with the default value.
______________________________________________________________________
Question 12
Which of the following statements about local variables is true?
Ans) A compilation error results when a local variable is accessed before it is initialized.
Explanation:
Even if we didn’t initialize the during compilation instance variables will be initialized with their
default values.
But if we want to use local variables compulsory we have to initialize it.If not we will get
compilation error.
______________________________________________________________________
Question 13
Analyze the code shown below and indicate which of the following is true:
class Quiz1E
{
private double variable;
public Quiz1E(double variable)
{
variable = variable;
}
}
Ans)
The program will compile, but you cannot create an object of Quiz1E with a specified value for
variable
Explanation:
As we didn’t provide ‘this’ so the variable will not get initialized.
We wont get any compilation error.But the instance variable value of Quiz1E class will be
initialized with the default values by the java compiler.So as it is double data type it will be
initialized with 0.0
______________________________________________________________________
Question 14
Which of the following is true of public methods?
Ans) They can only be accessed by methods in a different package
Explanation:
The scope of the public access specifier is global.So we can access public methods from
anywhere like with in the class or from with in the package or from outside the package.
______________________________________________________________________
Question 15
Which of the following statements is true about an immutable object?
Ans) The contents of an immutable object cannot be modified
Explanation:
Immutable:
the state or contents of an object cannot be changed or modified.best example for this is String
class .We cannot change the contents of the String class Object contents.
______________________________________________________________________
Question 16
What is the output of the program shown below?
public class Quiz1F
{
private static int i = 0;
public static void main(String[] args)
{
{
int i = 3;
}
System.out.println("i is " + i);
}
}
Ans) i is 0
Explanation:
The scope of the local variable is confined only to the method itself in which it has been
declared.
So if we print ‘i’ 0 will be displayed as output.which is the value of the static variable i.as we
declared private static int i = 0;
______________________________________________________________________
Question 17
Which of the following statements is true of the reserved word this?
Ans) It can be only used in instance methods and constructors
Explanation:
This refer to the current class instance variables.We can use ‘this’ to initialize the instance
variables.
______________________________________________________________________
Question 18
Which of the following statements is true about the class shown below?
public class Quiz1G
{
private void method()
{
}
public static void main(String[] args)
{
method();
}
}
Ans) It won't compile because method needs to be static
Explanation:
First the program wont compile.because we didn’t declare that method as static.To solve the
error we have to declare the method as static.
privatestaticvoid method()
{
System.out.println("x");
}
______________________________________________________________________
Question 19
Which of the following statements is true of private instance variables?
Ans) They can accessed in any instance method in the same class
Explanation:
The scope of the private is confined to the class itself.We can access the private variables only
with in the class in which they have been declared.We can access private instance variables in
any method of the same class.
______________________________________________________________________
Question 20
Which of the following statements about class (static) variables is correct?
Ans) There is only one copy of each class variable that is shared by all instances of the class
Explanation:
Static variable:Only one copy of static variable is shared by all the instances of the class.if we
modified the value of static variable in one object then it will reflects in other objects of the same
class also.
______________________________________________________________

More Related Content

PDF
What is a constructorAns)A constructor is also type of method whi.pdf
PPTX
Object Oriented Programming using C++ / C Plus Plus QUIZ
PDF
FIB MIT208.pdf
DOCX
Module 01 – Basics of StatisticsClass Objectives· Define and ca.docx
DOCX
Cpcs 203 -array-problems
DOCX
Core java notes with examples
DOCX
Assessment 3 – Hypothesis, Effect Size, Power, and t Tests.docx
PDF
E4
What is a constructorAns)A constructor is also type of method whi.pdf
Object Oriented Programming using C++ / C Plus Plus QUIZ
FIB MIT208.pdf
Module 01 – Basics of StatisticsClass Objectives· Define and ca.docx
Cpcs 203 -array-problems
Core java notes with examples
Assessment 3 – Hypothesis, Effect Size, Power, and t Tests.docx
E4

Similar to Question 1How many parameters does a default constructor haveAn.pdf (19)

DOCX
Exercise1[5points]Create the following classe
DOCX
Tameeka Final Exam (Answer Key)1.Solve the following line.docx
DOCX
Tameeka Final Exam (Answer Key)1.Solve the following line.docx
PDF
Accessing non static members from the main
PDF
Accessing non static members from the main
DOC
08review (1)
PPTX
MOD-3-Q4-REVIEWER.pptxhaarhstisdjdkd6pdl7d
DOCX
Name________________________________________________ Block________.docx
DOCX
Question 1 1 pts Skip to question text.As part of a bank account.docx
DOCX
CIS 407 STUDY Inspiring Innovation--cis407study.com
DOC
Delphi qa
PPTX
Deciphering the Ruby Object Model
PDF
Final Report
PPTX
Introduction to Ruby’s Reflection API
DOCX
Practice Test 5B Multinomial Experiments and Contingency Tables
DOCX
Practice Test 5B Multinomial Experiments and Contingency Tables
PPTX
Lecture 5
PPTX
Hemajava
Exercise1[5points]Create the following classe
Tameeka Final Exam (Answer Key)1.Solve the following line.docx
Tameeka Final Exam (Answer Key)1.Solve the following line.docx
Accessing non static members from the main
Accessing non static members from the main
08review (1)
MOD-3-Q4-REVIEWER.pptxhaarhstisdjdkd6pdl7d
Name________________________________________________ Block________.docx
Question 1 1 pts Skip to question text.As part of a bank account.docx
CIS 407 STUDY Inspiring Innovation--cis407study.com
Delphi qa
Deciphering the Ruby Object Model
Final Report
Introduction to Ruby’s Reflection API
Practice Test 5B Multinomial Experiments and Contingency Tables
Practice Test 5B Multinomial Experiments and Contingency Tables
Lecture 5
Hemajava
Ad

More from arccreation001 (20)

PDF
SOURCE CODEimport java.util.Iterator;public class CircularLinke.pdf
PDF
2) In Autocrine signalling, reception of a signal released by the sa.pdf
PDF
Volatility Distillation separates out different .pdf
PDF
The first one has Van der Waals interactions sinc.pdf
PDF
Supersaturated actually. There is more solvent th.pdf
PDF
In optics, a virtual image is an image in which t.pdf
PDF
1) Political orientation and ideas are the main reasons behind count.pdf
PDF
Molarity = moles volume in L Molarity = 0.0342.pdf
PDF
The tracheal system in insects and gills in fishes are both helps th.pdf
PDF
The answer is D. ChemoorganoheterotrophCow is a chemoorganohetero.pdf
PDF
The A and B chains of human insulin are cloned in separate plasmids .pdf
PDF
Rio de Janeiro is a city located on Brazils south-east coast. It i.pdf
PDF
Othello.javapackage othello;import core.Game; import userInter.pdf
PDF
1.Types of Computer Information SystemsThere are four basic type.pdf
PDF
Microbiome of human bodyResearchers currently studying human norm.pdf
PDF
Na2SeO3 --- 2 Na+ + SeO32- 0.08              0.16       0.08 .pdf
PDF
It is an important to understand the early stages of reproduction. W.pdf
PDF
Let the normal gene be represented by P, and the two mutations be re.pdf
PDF
Imagine you are an Information Systems Security Officer for a medium.pdf
PDF
Each water molecule has 4 hydrogen bonds holding .pdf
SOURCE CODEimport java.util.Iterator;public class CircularLinke.pdf
2) In Autocrine signalling, reception of a signal released by the sa.pdf
Volatility Distillation separates out different .pdf
The first one has Van der Waals interactions sinc.pdf
Supersaturated actually. There is more solvent th.pdf
In optics, a virtual image is an image in which t.pdf
1) Political orientation and ideas are the main reasons behind count.pdf
Molarity = moles volume in L Molarity = 0.0342.pdf
The tracheal system in insects and gills in fishes are both helps th.pdf
The answer is D. ChemoorganoheterotrophCow is a chemoorganohetero.pdf
The A and B chains of human insulin are cloned in separate plasmids .pdf
Rio de Janeiro is a city located on Brazils south-east coast. It i.pdf
Othello.javapackage othello;import core.Game; import userInter.pdf
1.Types of Computer Information SystemsThere are four basic type.pdf
Microbiome of human bodyResearchers currently studying human norm.pdf
Na2SeO3 --- 2 Na+ + SeO32- 0.08              0.16       0.08 .pdf
It is an important to understand the early stages of reproduction. W.pdf
Let the normal gene be represented by P, and the two mutations be re.pdf
Imagine you are an Information Systems Security Officer for a medium.pdf
Each water molecule has 4 hydrogen bonds holding .pdf
Ad

Recently uploaded (20)

PDF
ANTIBIOTICS.pptx.pdf………………… xxxxxxxxxxxxx
PDF
The Lost Whites of Pakistan by Jahanzaib Mughal.pdf
PDF
grade 11-chemistry_fetena_net_5883.pdf teacher guide for all student
PDF
STATICS OF THE RIGID BODIES Hibbelers.pdf
PDF
Supply Chain Operations Speaking Notes -ICLT Program
PDF
2.FourierTransform-ShortQuestionswithAnswers.pdf
PPTX
GDM (1) (1).pptx small presentation for students
PDF
Chapter 2 Heredity, Prenatal Development, and Birth.pdf
PDF
GENETICS IN BIOLOGY IN SECONDARY LEVEL FORM 3
PPTX
Tissue processing ( HISTOPATHOLOGICAL TECHNIQUE
PDF
Chinmaya Tiranga quiz Grand Finale.pdf
PPTX
Final Presentation General Medicine 03-08-2024.pptx
PPTX
PPT- ENG7_QUARTER1_LESSON1_WEEK1. IMAGERY -DESCRIPTIONS pptx.pptx
PPTX
human mycosis Human fungal infections are called human mycosis..pptx
PPTX
1st Inaugural Professorial Lecture held on 19th February 2020 (Governance and...
PDF
FourierSeries-QuestionsWithAnswers(Part-A).pdf
PPTX
Presentation on HIE in infants and its manifestations
PPTX
Final Presentation General Medicine 03-08-2024.pptx
PDF
O7-L3 Supply Chain Operations - ICLT Program
PDF
102 student loan defaulters named and shamed – Is someone you know on the list?
ANTIBIOTICS.pptx.pdf………………… xxxxxxxxxxxxx
The Lost Whites of Pakistan by Jahanzaib Mughal.pdf
grade 11-chemistry_fetena_net_5883.pdf teacher guide for all student
STATICS OF THE RIGID BODIES Hibbelers.pdf
Supply Chain Operations Speaking Notes -ICLT Program
2.FourierTransform-ShortQuestionswithAnswers.pdf
GDM (1) (1).pptx small presentation for students
Chapter 2 Heredity, Prenatal Development, and Birth.pdf
GENETICS IN BIOLOGY IN SECONDARY LEVEL FORM 3
Tissue processing ( HISTOPATHOLOGICAL TECHNIQUE
Chinmaya Tiranga quiz Grand Finale.pdf
Final Presentation General Medicine 03-08-2024.pptx
PPT- ENG7_QUARTER1_LESSON1_WEEK1. IMAGERY -DESCRIPTIONS pptx.pptx
human mycosis Human fungal infections are called human mycosis..pptx
1st Inaugural Professorial Lecture held on 19th February 2020 (Governance and...
FourierSeries-QuestionsWithAnswers(Part-A).pdf
Presentation on HIE in infants and its manifestations
Final Presentation General Medicine 03-08-2024.pptx
O7-L3 Supply Chain Operations - ICLT Program
102 student loan defaulters named and shamed – Is someone you know on the list?

Question 1How many parameters does a default constructor haveAn.pdf

  • 1. Question 1 How many parameters does a default constructor have? Ans) It never has any Explanation: The default constructor doesn’t have any parameters.Thats why it is also called as Zero- Argumented constructor. Even The default constructor doesn’t return anything even void also. ___________________________________________________________________ Question 2 Which of the following statements is true about the class shown below? class Quiz1A { private int[] array = new int[10]; public int[] getArray() { return array; } } Ans) It is immutable Explanation: Here the getArray() method is not doing any operations inside it.It just returning an array.So it is also called as getter method. ______________________________________________________________________ Question 3 A method that is associated with an individual object is called __________. Ans) an instance method Explanation: For every class we can create many objects.If we want to call a method on object, we have to call a method by using the reference of it.That method is confined to that object only. ______________________________________________________________________ Question 4 Given the declaration Circle[] x = new Circle[10], which of the following statement is most accurate? Ans) x contains a reference to an array and each element in the array can hold a reference to a
  • 2. Circle object. Explanation: This array will hold the references of Circle class objects.It will not store objects. ______________________________________________________________________ Question 5 What is the output of the program shown below? public class Quiz1B { public static void main(String[] args) { Count count = new Count(); int times = 0; for (int i = 0; i < 100; i++) increment(count, times); System.out.println("times = " + times + " count = " + count.times); } public static void increment(Count count, int times) { count.times++; times++; } } class Count { int times; public Count() { times = 1; } } Ans) times = 100 count = 101
  • 3. Explanation: This for loop in the main method will be executed for 100 times.So the value of the variable of main method times will increased by 1 for each iteration.As the initial value of times is 0 and finally it will become 100.after 100 iterations As the initial value of instance variable of Count class is 1.After 100 iterations its value will become 101 ______________________________________________________________________ Question 6 When calling a method with an object argument, ___________ is passed. Ans) the reference of the object Explanation: We have to pass the reference of an object as argument while calling.not the copy or objects contents or else. ______________________________________________________________________ Question 7 Which of the following is not a property of a constructor? Ans) The name of a constructor can be chosen by the programmer Explanation: We can overload the constructor. The constructor is called and executed when we are creating an object by using new operator. The name of the constructor should be the name of the class.We cannot choose the name of the constructor. ______________________________________________________________________ Question 8 What is the output of the program shown below? public class Quiz1C { public static void main(String[] args) { int i = 1; StringBuilder s = new StringBuilder("s"); String t = "t"; someMethod(i, s, t); System.out.print("i = " + i + ", ");
  • 4. System.out.print("s = " + s + ", "); System.out.println("t = " + t); } private static void someMethod(int i, StringBuilder s, String t) { i++; s.append("s"); t += "t"; } } Ans) i = 2, s = ss, t = tt Explanation: We are calling the method someMethod(int i, StringBuilder s, String t) by passing the int variable,references of StringBuilder and String Inside that i value will be incremented by 1 Appending s to the content of StringBuilder Object. Concatenating t to the String “t” ______________________________________________________________________ Question 9 Which of the following statements is true about the order of methods in a class. Ans) They can be listed in any order Explanation: We can declare the methods inside the class in any order .there is no restrictions on the order of declaration of methods. ______________________________________________________________________ Question 10 Which of the following statements about constructors is true? Ans) A default constructor is provided automatically if no constructors are explicitly declared in the class Explanation: If we didnt provided any constructor in a class,the java compiler will provide the code for default constructor inside the class while compiling the class. ______________________________________________________________________ Question 11 Which of the following is true about the program shown below?
  • 5. class Quiz1D { private int x; public Quiz1D(int x) { this.x = x; } } Ans) If the this qualifier is removed, it will compile but won't initialize the instance variable Explanation: This refers to the current class instance variable.Even If we didn’t provide ‘this’ also our program will compile but the instance variable will not get initialized.So the instance variable will be initialized with the default value. ______________________________________________________________________ Question 12 Which of the following statements about local variables is true? Ans) A compilation error results when a local variable is accessed before it is initialized. Explanation: Even if we didn’t initialize the during compilation instance variables will be initialized with their default values. But if we want to use local variables compulsory we have to initialize it.If not we will get compilation error. ______________________________________________________________________ Question 13 Analyze the code shown below and indicate which of the following is true: class Quiz1E { private double variable; public Quiz1E(double variable) { variable = variable; }
  • 6. } Ans) The program will compile, but you cannot create an object of Quiz1E with a specified value for variable Explanation: As we didn’t provide ‘this’ so the variable will not get initialized. We wont get any compilation error.But the instance variable value of Quiz1E class will be initialized with the default values by the java compiler.So as it is double data type it will be initialized with 0.0 ______________________________________________________________________ Question 14 Which of the following is true of public methods? Ans) They can only be accessed by methods in a different package Explanation: The scope of the public access specifier is global.So we can access public methods from anywhere like with in the class or from with in the package or from outside the package. ______________________________________________________________________ Question 15 Which of the following statements is true about an immutable object? Ans) The contents of an immutable object cannot be modified Explanation: Immutable: the state or contents of an object cannot be changed or modified.best example for this is String class .We cannot change the contents of the String class Object contents. ______________________________________________________________________ Question 16 What is the output of the program shown below? public class Quiz1F { private static int i = 0; public static void main(String[] args) { { int i = 3;
  • 7. } System.out.println("i is " + i); } } Ans) i is 0 Explanation: The scope of the local variable is confined only to the method itself in which it has been declared. So if we print ‘i’ 0 will be displayed as output.which is the value of the static variable i.as we declared private static int i = 0; ______________________________________________________________________ Question 17 Which of the following statements is true of the reserved word this? Ans) It can be only used in instance methods and constructors Explanation: This refer to the current class instance variables.We can use ‘this’ to initialize the instance variables. ______________________________________________________________________ Question 18 Which of the following statements is true about the class shown below? public class Quiz1G { private void method() { } public static void main(String[] args) { method(); } } Ans) It won't compile because method needs to be static Explanation: First the program wont compile.because we didn’t declare that method as static.To solve the error we have to declare the method as static.
  • 8. privatestaticvoid method() { System.out.println("x"); } ______________________________________________________________________ Question 19 Which of the following statements is true of private instance variables? Ans) They can accessed in any instance method in the same class Explanation: The scope of the private is confined to the class itself.We can access the private variables only with in the class in which they have been declared.We can access private instance variables in any method of the same class. ______________________________________________________________________ Question 20 Which of the following statements about class (static) variables is correct? Ans) There is only one copy of each class variable that is shared by all instances of the class Explanation: Static variable:Only one copy of static variable is shared by all the instances of the class.if we modified the value of static variable in one object then it will reflects in other objects of the same class also. ______________________________________________________________ Solution Question 1 How many parameters does a default constructor have? Ans) It never has any Explanation: The default constructor doesn’t have any parameters.Thats why it is also called as Zero- Argumented constructor. Even The default constructor doesn’t return anything even void also. ___________________________________________________________________ Question 2 Which of the following statements is true about the class shown below?
  • 9. class Quiz1A { private int[] array = new int[10]; public int[] getArray() { return array; } } Ans) It is immutable Explanation: Here the getArray() method is not doing any operations inside it.It just returning an array.So it is also called as getter method. ______________________________________________________________________ Question 3 A method that is associated with an individual object is called __________. Ans) an instance method Explanation: For every class we can create many objects.If we want to call a method on object, we have to call a method by using the reference of it.That method is confined to that object only. ______________________________________________________________________ Question 4 Given the declaration Circle[] x = new Circle[10], which of the following statement is most accurate? Ans) x contains a reference to an array and each element in the array can hold a reference to a Circle object. Explanation: This array will hold the references of Circle class objects.It will not store objects. ______________________________________________________________________ Question 5 What is the output of the program shown below? public class Quiz1B { public static void main(String[] args) { Count count = new Count();
  • 10. int times = 0; for (int i = 0; i < 100; i++) increment(count, times); System.out.println("times = " + times + " count = " + count.times); } public static void increment(Count count, int times) { count.times++; times++; } } class Count { int times; public Count() { times = 1; } } Ans) times = 100 count = 101 Explanation: This for loop in the main method will be executed for 100 times.So the value of the variable of main method times will increased by 1 for each iteration.As the initial value of times is 0 and finally it will become 100.after 100 iterations As the initial value of instance variable of Count class is 1.After 100 iterations its value will become 101 ______________________________________________________________________ Question 6 When calling a method with an object argument, ___________ is passed. Ans) the reference of the object Explanation: We have to pass the reference of an object as argument while calling.not the copy or objects
  • 11. contents or else. ______________________________________________________________________ Question 7 Which of the following is not a property of a constructor? Ans) The name of a constructor can be chosen by the programmer Explanation: We can overload the constructor. The constructor is called and executed when we are creating an object by using new operator. The name of the constructor should be the name of the class.We cannot choose the name of the constructor. ______________________________________________________________________ Question 8 What is the output of the program shown below? public class Quiz1C { public static void main(String[] args) { int i = 1; StringBuilder s = new StringBuilder("s"); String t = "t"; someMethod(i, s, t); System.out.print("i = " + i + ", "); System.out.print("s = " + s + ", "); System.out.println("t = " + t); } private static void someMethod(int i, StringBuilder s, String t) { i++; s.append("s"); t += "t"; } } Ans) i = 2, s = ss, t = tt
  • 12. Explanation: We are calling the method someMethod(int i, StringBuilder s, String t) by passing the int variable,references of StringBuilder and String Inside that i value will be incremented by 1 Appending s to the content of StringBuilder Object. Concatenating t to the String “t” ______________________________________________________________________ Question 9 Which of the following statements is true about the order of methods in a class. Ans) They can be listed in any order Explanation: We can declare the methods inside the class in any order .there is no restrictions on the order of declaration of methods. ______________________________________________________________________ Question 10 Which of the following statements about constructors is true? Ans) A default constructor is provided automatically if no constructors are explicitly declared in the class Explanation: If we didnt provided any constructor in a class,the java compiler will provide the code for default constructor inside the class while compiling the class. ______________________________________________________________________ Question 11 Which of the following is true about the program shown below? class Quiz1D { private int x; public Quiz1D(int x) { this.x = x; } } Ans) If the this qualifier is removed, it will compile but won't initialize the instance variable Explanation:
  • 13. This refers to the current class instance variable.Even If we didn’t provide ‘this’ also our program will compile but the instance variable will not get initialized.So the instance variable will be initialized with the default value. ______________________________________________________________________ Question 12 Which of the following statements about local variables is true? Ans) A compilation error results when a local variable is accessed before it is initialized. Explanation: Even if we didn’t initialize the during compilation instance variables will be initialized with their default values. But if we want to use local variables compulsory we have to initialize it.If not we will get compilation error. ______________________________________________________________________ Question 13 Analyze the code shown below and indicate which of the following is true: class Quiz1E { private double variable; public Quiz1E(double variable) { variable = variable; } } Ans) The program will compile, but you cannot create an object of Quiz1E with a specified value for variable Explanation: As we didn’t provide ‘this’ so the variable will not get initialized. We wont get any compilation error.But the instance variable value of Quiz1E class will be initialized with the default values by the java compiler.So as it is double data type it will be initialized with 0.0 ______________________________________________________________________ Question 14 Which of the following is true of public methods?
  • 14. Ans) They can only be accessed by methods in a different package Explanation: The scope of the public access specifier is global.So we can access public methods from anywhere like with in the class or from with in the package or from outside the package. ______________________________________________________________________ Question 15 Which of the following statements is true about an immutable object? Ans) The contents of an immutable object cannot be modified Explanation: Immutable: the state or contents of an object cannot be changed or modified.best example for this is String class .We cannot change the contents of the String class Object contents. ______________________________________________________________________ Question 16 What is the output of the program shown below? public class Quiz1F { private static int i = 0; public static void main(String[] args) { { int i = 3; } System.out.println("i is " + i); } } Ans) i is 0 Explanation: The scope of the local variable is confined only to the method itself in which it has been declared. So if we print ‘i’ 0 will be displayed as output.which is the value of the static variable i.as we declared private static int i = 0; ______________________________________________________________________ Question 17
  • 15. Which of the following statements is true of the reserved word this? Ans) It can be only used in instance methods and constructors Explanation: This refer to the current class instance variables.We can use ‘this’ to initialize the instance variables. ______________________________________________________________________ Question 18 Which of the following statements is true about the class shown below? public class Quiz1G { private void method() { } public static void main(String[] args) { method(); } } Ans) It won't compile because method needs to be static Explanation: First the program wont compile.because we didn’t declare that method as static.To solve the error we have to declare the method as static. privatestaticvoid method() { System.out.println("x"); } ______________________________________________________________________ Question 19 Which of the following statements is true of private instance variables? Ans) They can accessed in any instance method in the same class Explanation: The scope of the private is confined to the class itself.We can access the private variables only with in the class in which they have been declared.We can access private instance variables in any method of the same class.
  • 16. ______________________________________________________________________ Question 20 Which of the following statements about class (static) variables is correct? Ans) There is only one copy of each class variable that is shared by all instances of the class Explanation: Static variable:Only one copy of static variable is shared by all the instances of the class.if we modified the value of static variable in one object then it will reflects in other objects of the same class also. ______________________________________________________________