Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
0% found this document useful (0 votes)
1K views

Test Your Understanding - Classes and Objects (Copy) - Attempt Review

The document summarizes a quiz that the user completed on classes and objects in Java. The summary includes that the user passed the quiz with a score of 7.67/8.00 or 95.83% and there were 8 multiple choice questions on topics like access specifiers, getters and setters, and using private variables.

Uploaded by

19K41A0 450
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
1K views

Test Your Understanding - Classes and Objects (Copy) - Attempt Review

The document summarizes a quiz that the user completed on classes and objects in Java. The summary includes that the user passed the quiz with a score of 7.67/8.00 or 95.83% and there were 8 multiple choice questions on topics like access specifiers, getters and setters, and using private variables.

Uploaded by

19K41A0 450
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 8

11/14/23, 3:40 PM Test Your understanding - Classes and Objects (copy): Attempt review


 Dashboard / App Dev / Stage - 1 / Java Programming / Classes and Objects, Packages

Quiz review
Started on Sunday, 12 November 2023, 4:20 PM
State Finished
Completed on Sunday, 12 November 2023, 4:31 PM
Time taken 10 mins 19 secs
Marks 7.67/8.00
Grade 95.83 out of 100.00
Feedback Congratulations!!! You have passed by securing more than 80%

Question 1
Correct

Mark 1.00 out of 1.00

42763
___ and _____ are the access specifiers that can be applied to top level Class.

Select one or more:


a. protected

b. default

c. public

d. virtual

42763
Your answer is correct.

The correct answers are: default, public

42763

https://accenturelearning.tekstac.com/mod/quiz/review.php?attempt=684946&cmid=1206 1/9
11/14/23, 3:40 PM Test Your understanding - Classes and Objects (copy): Attempt review

Question 2
Partially correct

Mark 0.67 out of 1.00

Analyze the below program and choose the appropriate code so that it produces the below output:
0
101
class Book {

private int bookId;


private double bookPrice;
public int getBookId() {
return bookId;

public void setBookId(int bookId) {

42763
this.bookId = bookId;

}
public double getBookPrice() {

return bookPrice;

}
public void setBookPrice(double bookPrice) {

this.bookPrice = bookPrice;
}

42763
public class Test {
public static void main(String a[]) {

Book bobj=new Book();

System.out.println(bobj.getBookPrice()); 

bobj.setBookId(101); 

System.out.println(bobj.getBookId()); 

}
}

42763
Note : Same option can be used multiple times. Analyse and use the correct option

Your answer is partially correct.

You have correctly selected 2.


The correct answer is:

Analyze the below program and choose the appropriate code so that it produces the below output:
0
101

class Book {
private int bookId;
private double bookPrice;

public int getBookId() {

https://accenturelearning.tekstac.com/mod/quiz/review.php?attempt=684946&cmid=1206 2/9
11/14/23, 3:40 PM Test Your understanding - Classes and Objects (copy): Attempt review
return bookId;
}

public void setBookId(int bookId) {


this.bookId = bookId;

public double getBookPrice() {


return bookPrice;

}
public void setBookPrice(double bookPrice) {
this.bookPrice = bookPrice;

}
}
public class Test {
public static void main(String a[]) {

42763
Book bobj=new Book();
[System.out.println(bobj.getBookId());]

[bobj.setBookId(101);]

[System.out.println(bobj.getBookId());]
}

Note : Same option can be used multiple times. Analyse and use the correct option

42763

42763

https://accenturelearning.tekstac.com/mod/quiz/review.php?attempt=684946&cmid=1206 3/9
11/14/23, 3:40 PM Test Your understanding - Classes and Objects (copy): Attempt review

Question 3
Correct

Mark 1.00 out of 1.00

Choose the correct option so that the code runs without any compilation errors

a. public void setSalary(float salary1){

public class Employee {


private int employeeId;
private float salary;

{
if (salary > 0) {
salary = salary1;
}

42763
b. public class Employee {

public void setSalary(float salary1) {

private int employeeId;


private float salary;

if (salary > 0) {
salary = salary1;

}
}

c. public class Employee {

private int employeeId;


42763 

private float salary;

public void setSalary(float salary1) {


if (salary > 0) {

salary = salary1;
}
}
}

d. public class Employee {

private int employeeId;


42763
private float salary;
if(salary>0)
{

salary = salary1;
}
public void setSalary(float salary1) {

}
}

Your answer is correct.

https://accenturelearning.tekstac.com/mod/quiz/review.php?attempt=684946&cmid=1206 4/9
11/14/23, 3:40 PM Test Your understanding - Classes and Objects (copy): Attempt review
The correct answer is:
public class Employee {

private int employeeId;


private float salary;

public void setSalary(float salary1) {


if (salary > 0) {

salary = salary1;
}
}

Question 4
Correct

Mark 1.00 out of 1.00

class Sample{

private double num = 100;


42763
private int square(int a){
return a*a;

}
public class Test{

public static void main(String args[]){


Sample obj = new Sample();

System.out.println(obj.num);

System.out.println(obj.square(10));
42763
}

Select one:
a. Run time error

b. Executes but no output


c. 100

d. Compile time error

42763
Your answer is correct.

The correct answer is: Compile time error

https://accenturelearning.tekstac.com/mod/quiz/review.php?attempt=684946&cmid=1206 5/9
11/14/23, 3:40 PM Test Your understanding - Classes and Objects (copy): Attempt review

Question 5
Correct

Mark 1.00 out of 1.00

Choose the appropriate access specifier for the attribute value so that it can be accessed from anywhere.

class Test
{

public  int value;

Your answer is correct.

The correct answer is:


Choose the appropriate access specifier for the attribute value so that it can be accessed from anywhere.

class Test

42763
{
[public] int value;

Question 6
Correct

Mark 1.00 out of 1.00

Choose the appropriate return type for the getters and setters provided below.

42763
class Test

private int value;

public void  setValue(int value){//some code}

public int  getValue(){//some code}

Your answer is correct.

42763
The correct answer is:
Choose the appropriate return type for the getters and setters provided below.
class Test

{
private int value;
public [void] setValue(int value){//some code}

public [int] getValue(){//some code}


}

https://accenturelearning.tekstac.com/mod/quiz/review.php?attempt=684946&cmid=1206 6/9
11/14/23, 3:40 PM Test Your understanding - Classes and Objects (copy): Attempt review

Question 7
Correct

Mark 1.00 out of 1.00

Consider the below code snippet and determine the output.


class Student

{ private int studentId;


private float average;
}

class Test
{
public static void main(String a[])
{

Student s=new Student();


s.studentId=123;

}
42763
System.out.println(s.studentId);

Select one:
a. Any value

b. 1

c. 0

d. Compile time error


42763
Your answer is correct.
Private variables can be accessed only within the class. They cannot be accessed outside the class.

The correct answer is: Compile time error

42763

https://accenturelearning.tekstac.com/mod/quiz/review.php?attempt=684946&cmid=1206 7/9
11/14/23, 3:40 PM Test Your understanding - Classes and Objects (copy): Attempt review

Question 8
Correct

Mark 1.00 out of 1.00

The below code snippet shows an error


cannot find symbol:

System.out.println("BookId:"+bobj.getId());
public class Book {
private int bookId;

private double bookPrice;


public int getBookId() {
return bookId;
}

public void setBookId(int bookId) {


this.bookId = bookId;

} 42763
public double getBookPrice() {
return bookPrice;

public void setBookPrice(double bookPrice) {


this.bookPrice = bookPrice;

}
}

public class Test {

42763
public static void main(String[] args) {
Book bobj=new Book();

bobj.setBookId(123);
bobj.setBookPrice(500);
System.out.println("BookId:"+bobj.getId());
System.out.println("BookPrice:"+bobj.getBookPrice());

}
}

42763
Analyze the above code and select the correct reason for the error.

Select one:
a. “+” symbol should not be used in System.out.println

b. bobj is not initialized

c. getId method is not present in the book class

d. Getter method should not be called inside System.out.println

Your answer is correct.


When we specify the methodname or variablename or classname wrongly,then we will get an error “cannot find symbol”. The compiler
tries to fetch the methodname "getId" from the book class, where it is not defined.

https://accenturelearning.tekstac.com/mod/quiz/review.php?attempt=684946&cmid=1206 8/9

You might also like