SlideShare a Scribd company logo
1 of 16
Download to read offline
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

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

Tameeka Final Exam (Answer Key)1.Solve the following line.docx
Tameeka Final Exam (Answer Key)1.Solve the following line.docxTameeka Final Exam (Answer Key)1.Solve the following line.docx
Tameeka Final Exam (Answer Key)1.Solve the following line.docx
deanmtaylor1545
 
Tameeka Final Exam (Answer Key)1.Solve the following line.docx
Tameeka Final Exam (Answer Key)1.Solve the following line.docxTameeka Final Exam (Answer Key)1.Solve the following line.docx
Tameeka Final Exam (Answer Key)1.Solve the following line.docx
bradburgess22840
 
Name________________________________________________ Block________.docx
Name________________________________________________ Block________.docxName________________________________________________ Block________.docx
Name________________________________________________ Block________.docx
hallettfaustina
 
Question 1 1 pts Skip to question text.As part of a bank account.docx
Question 1 1 pts Skip to question text.As part of a bank account.docxQuestion 1 1 pts Skip to question text.As part of a bank account.docx
Question 1 1 pts Skip to question text.As part of a bank account.docx
amrit47
 
Final Report
Final ReportFinal Report
Final Report
Aman Soni
 

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

Tameeka Final Exam (Answer Key)1.Solve the following line.docx
Tameeka Final Exam (Answer Key)1.Solve the following line.docxTameeka Final Exam (Answer Key)1.Solve the following line.docx
Tameeka Final Exam (Answer Key)1.Solve the following line.docx
 
Tameeka Final Exam (Answer Key)1.Solve the following line.docx
Tameeka Final Exam (Answer Key)1.Solve the following line.docxTameeka 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 mainAccessing non static members from the main
Accessing non static members from the main
 
Accessing non static members from the main
Accessing non static members from the mainAccessing non static members from the main
Accessing non static members from the main
 
08review (1)
08review (1)08review (1)
08review (1)
 
Name________________________________________________ Block________.docx
Name________________________________________________ Block________.docxName________________________________________________ Block________.docx
Name________________________________________________ Block________.docx
 
Question 1 1 pts Skip to question text.As part of a bank account.docx
Question 1 1 pts Skip to question text.As part of a bank account.docxQuestion 1 1 pts Skip to question text.As part of a bank account.docx
Question 1 1 pts Skip to question text.As part of a bank account.docx
 
CIS 407 STUDY Inspiring Innovation--cis407study.com
CIS 407 STUDY Inspiring Innovation--cis407study.comCIS 407 STUDY Inspiring Innovation--cis407study.com
CIS 407 STUDY Inspiring Innovation--cis407study.com
 
Delphi qa
Delphi qaDelphi qa
Delphi qa
 
Deciphering the Ruby Object Model
Deciphering the Ruby Object ModelDeciphering the Ruby Object Model
Deciphering the Ruby Object Model
 
Final Report
Final ReportFinal Report
Final Report
 
Introduction to Ruby’s Reflection API
Introduction to Ruby’s Reflection APIIntroduction to Ruby’s Reflection API
Introduction to Ruby’s Reflection API
 
Guide
GuideGuide
Guide
 
Practice Test 5B Multinomial Experiments and Contingency Tables
Practice Test 5B Multinomial Experiments and Contingency TablesPractice Test 5B Multinomial Experiments and Contingency Tables
Practice Test 5B Multinomial Experiments and Contingency Tables
 
Practice Test 5B Multinomial Experiments and Contingency Tables
Practice Test 5B Multinomial Experiments and Contingency TablesPractice Test 5B Multinomial Experiments and Contingency Tables
Practice Test 5B Multinomial Experiments and Contingency Tables
 
Lecture 5
Lecture 5Lecture 5
Lecture 5
 
Hemajava
HemajavaHemajava
Hemajava
 
CIS 1403 lab 3 functions and methods in Java
CIS 1403 lab 3 functions and methods in JavaCIS 1403 lab 3 functions and methods in Java
CIS 1403 lab 3 functions and methods in Java
 
Rechecking SharpDevelop: Any New Bugs?
Rechecking SharpDevelop: Any New Bugs?Rechecking SharpDevelop: Any New Bugs?
Rechecking SharpDevelop: Any New Bugs?
 

More from arccreation001

SOURCE CODEimport java.util.Iterator;public class CircularLinke.pdf
SOURCE CODEimport java.util.Iterator;public class CircularLinke.pdfSOURCE CODEimport java.util.Iterator;public class CircularLinke.pdf
SOURCE CODEimport java.util.Iterator;public class CircularLinke.pdf
arccreation001
 
In optics, a virtual image is an image in which t.pdf
                     In optics, a virtual image is an image in which t.pdf                     In optics, a virtual image is an image in which t.pdf
In optics, a virtual image is an image in which t.pdf
arccreation001
 
1) Political orientation and ideas are the main reasons behind count.pdf
1) Political orientation and ideas are the main reasons behind count.pdf1) Political orientation and ideas are the main reasons behind count.pdf
1) Political orientation and ideas are the main reasons behind count.pdf
arccreation001
 
The tracheal system in insects and gills in fishes are both helps th.pdf
The tracheal system in insects and gills in fishes are both helps th.pdfThe tracheal system in insects and gills in fishes are both helps th.pdf
The tracheal system in insects and gills in fishes are both helps th.pdf
arccreation001
 
Rio de Janeiro is a city located on Brazils south-east coast. It i.pdf
Rio de Janeiro is a city located on Brazils south-east coast. It i.pdfRio de Janeiro is a city located on Brazils south-east coast. It i.pdf
Rio de Janeiro is a city located on Brazils south-east coast. It i.pdf
arccreation001
 
Othello.javapackage othello;import core.Game; import userInter.pdf
Othello.javapackage othello;import core.Game; import userInter.pdfOthello.javapackage othello;import core.Game; import userInter.pdf
Othello.javapackage othello;import core.Game; import userInter.pdf
arccreation001
 
1.Types of Computer Information SystemsThere are four basic type.pdf
1.Types of Computer Information SystemsThere are four basic type.pdf1.Types of Computer Information SystemsThere are four basic type.pdf
1.Types of Computer Information SystemsThere are four basic type.pdf
arccreation001
 
Microbiome of human bodyResearchers currently studying human norm.pdf
Microbiome of human bodyResearchers currently studying human norm.pdfMicrobiome of human bodyResearchers currently studying human norm.pdf
Microbiome of human bodyResearchers currently studying human norm.pdf
arccreation001
 
It is an important to understand the early stages of reproduction. W.pdf
It is an important to understand the early stages of reproduction. W.pdfIt is an important to understand the early stages of reproduction. W.pdf
It is an important to understand the early stages of reproduction. W.pdf
arccreation001
 
Let the normal gene be represented by P, and the two mutations be re.pdf
Let the normal gene be represented by P, and the two mutations be re.pdfLet the normal gene be represented by P, and the two mutations be re.pdf
Let the normal gene be represented by P, and the two mutations be re.pdf
arccreation001
 
Imagine you are an Information Systems Security Officer for a medium.pdf
Imagine you are an Information Systems Security Officer for a medium.pdfImagine you are an Information Systems Security Officer for a medium.pdf
Imagine you are an Information Systems Security Officer for a medium.pdf
arccreation001
 

More from arccreation001 (20)

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

Recently uploaded

1029 - Danh muc Sach Giao Khoa 10 . pdf
1029 -  Danh muc Sach Giao Khoa 10 . pdf1029 -  Danh muc Sach Giao Khoa 10 . pdf
1029 - Danh muc Sach Giao Khoa 10 . pdf
QucHHunhnh
 
Vishram Singh - Textbook of Anatomy Upper Limb and Thorax.. Volume 1 (1).pdf
Vishram Singh - Textbook of Anatomy  Upper Limb and Thorax.. Volume 1 (1).pdfVishram Singh - Textbook of Anatomy  Upper Limb and Thorax.. Volume 1 (1).pdf
Vishram Singh - Textbook of Anatomy Upper Limb and Thorax.. Volume 1 (1).pdf
ssuserdda66b
 
The basics of sentences session 3pptx.pptx
The basics of sentences session 3pptx.pptxThe basics of sentences session 3pptx.pptx
The basics of sentences session 3pptx.pptx
heathfieldcps1
 
Salient Features of India constitution especially power and functions
Salient Features of India constitution especially power and functionsSalient Features of India constitution especially power and functions
Salient Features of India constitution especially power and functions
KarakKing
 

Recently uploaded (20)

Understanding Accommodations and Modifications
Understanding  Accommodations and ModificationsUnderstanding  Accommodations and Modifications
Understanding Accommodations and Modifications
 
Python Notes for mca i year students osmania university.docx
Python Notes for mca i year students osmania university.docxPython Notes for mca i year students osmania university.docx
Python Notes for mca i year students osmania university.docx
 
This PowerPoint helps students to consider the concept of infinity.
This PowerPoint helps students to consider the concept of infinity.This PowerPoint helps students to consider the concept of infinity.
This PowerPoint helps students to consider the concept of infinity.
 
Mixin Classes in Odoo 17 How to Extend Models Using Mixin Classes
Mixin Classes in Odoo 17  How to Extend Models Using Mixin ClassesMixin Classes in Odoo 17  How to Extend Models Using Mixin Classes
Mixin Classes in Odoo 17 How to Extend Models Using Mixin Classes
 
Fostering Friendships - Enhancing Social Bonds in the Classroom
Fostering Friendships - Enhancing Social Bonds  in the ClassroomFostering Friendships - Enhancing Social Bonds  in the Classroom
Fostering Friendships - Enhancing Social Bonds in the Classroom
 
Food safety_Challenges food safety laboratories_.pdf
Food safety_Challenges food safety laboratories_.pdfFood safety_Challenges food safety laboratories_.pdf
Food safety_Challenges food safety laboratories_.pdf
 
Unit-IV- Pharma. Marketing Channels.pptx
Unit-IV- Pharma. Marketing Channels.pptxUnit-IV- Pharma. Marketing Channels.pptx
Unit-IV- Pharma. Marketing Channels.pptx
 
FSB Advising Checklist - Orientation 2024
FSB Advising Checklist - Orientation 2024FSB Advising Checklist - Orientation 2024
FSB Advising Checklist - Orientation 2024
 
How to Manage Global Discount in Odoo 17 POS
How to Manage Global Discount in Odoo 17 POSHow to Manage Global Discount in Odoo 17 POS
How to Manage Global Discount in Odoo 17 POS
 
1029 - Danh muc Sach Giao Khoa 10 . pdf
1029 -  Danh muc Sach Giao Khoa 10 . pdf1029 -  Danh muc Sach Giao Khoa 10 . pdf
1029 - Danh muc Sach Giao Khoa 10 . pdf
 
Vishram Singh - Textbook of Anatomy Upper Limb and Thorax.. Volume 1 (1).pdf
Vishram Singh - Textbook of Anatomy  Upper Limb and Thorax.. Volume 1 (1).pdfVishram Singh - Textbook of Anatomy  Upper Limb and Thorax.. Volume 1 (1).pdf
Vishram Singh - Textbook of Anatomy Upper Limb and Thorax.. Volume 1 (1).pdf
 
TỔNG ÔN TẬP THI VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGỮ Â...
TỔNG ÔN TẬP THI VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGỮ Â...TỔNG ÔN TẬP THI VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGỮ Â...
TỔNG ÔN TẬP THI VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGỮ Â...
 
Unit-V; Pricing (Pharma Marketing Management).pptx
Unit-V; Pricing (Pharma Marketing Management).pptxUnit-V; Pricing (Pharma Marketing Management).pptx
Unit-V; Pricing (Pharma Marketing Management).pptx
 
Accessible Digital Futures project (20/03/2024)
Accessible Digital Futures project (20/03/2024)Accessible Digital Futures project (20/03/2024)
Accessible Digital Futures project (20/03/2024)
 
Unit-IV; Professional Sales Representative (PSR).pptx
Unit-IV; Professional Sales Representative (PSR).pptxUnit-IV; Professional Sales Representative (PSR).pptx
Unit-IV; Professional Sales Representative (PSR).pptx
 
Google Gemini An AI Revolution in Education.pptx
Google Gemini An AI Revolution in Education.pptxGoogle Gemini An AI Revolution in Education.pptx
Google Gemini An AI Revolution in Education.pptx
 
Towards a code of practice for AI in AT.pptx
Towards a code of practice for AI in AT.pptxTowards a code of practice for AI in AT.pptx
Towards a code of practice for AI in AT.pptx
 
Mehran University Newsletter Vol-X, Issue-I, 2024
Mehran University Newsletter Vol-X, Issue-I, 2024Mehran University Newsletter Vol-X, Issue-I, 2024
Mehran University Newsletter Vol-X, Issue-I, 2024
 
The basics of sentences session 3pptx.pptx
The basics of sentences session 3pptx.pptxThe basics of sentences session 3pptx.pptx
The basics of sentences session 3pptx.pptx
 
Salient Features of India constitution especially power and functions
Salient Features of India constitution especially power and functionsSalient Features of India constitution especially power and functions
Salient Features of India constitution especially power and functions
 

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. ______________________________________________________________