100% found this document useful (1 vote)
2K views5 pages

Test Your Understanding - Static (Copy) - Attempt Review

This document summarizes the results of a quiz on static methods and variables in Java. The quiz contained 5 multiple choice questions. The student scored 4.33 out of 5, getting 86.67% overall. Feedback indicated they passed by securing over 80%. Each question is briefly described, including the student's answer and feedback that their answer was correct.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
100% found this document useful (1 vote)
2K views5 pages

Test Your Understanding - Static (Copy) - Attempt Review

This document summarizes the results of a quiz on static methods and variables in Java. The quiz contained 5 multiple choice questions. The student scored 4.33 out of 5, getting 86.67% overall. Feedback indicated they passed by securing over 80%. Each question is briefly described, including the student's answer and feedback that their answer was correct.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 5

9/12/23, 9:22 PM Test your understanding - static (copy): Attempt review


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

Quiz review
Started on Tuesday, 12 September 2023, 9:11 PM
State Finished
Completed on Tuesday, 12 September 2023, 9:21 PM
Time taken 9 mins 41 secs
Marks 4.33/5.00
Grade 86.67 out of 100.00
Feedback
Congratulations!!! You have passed by securing more than 80%

Question 1

37547
Correct

Mark 1.00 out of 1.00

Match the following :

non static method Can access both static and non static members 

static method
Can access static members only 

37547
Your answer is correct.

The correct answer is: non static method → Can access both static and non static members, static method → Can access static members only

37547


https://accenturelearning.tekstac.com/mod/quiz/review.php?attempt=67961&cmid=1214#question-67961-4 1/5
9/12/23, 9:22 PM Test your understanding - static (copy): Attempt review

Question 2
Correct

Mark 1.00 out of 1.00

Observe the below code


public class Product
{
int productId;

String productName;
static int count = 0;

public Product(int pid,String name){


productId = pid;
productName=name;

37547
count++;

public static void main(String arg[]){

Product p1=new Product(101,"Screws");

System.out.println("Count is "+Product.count); 

Product p2=new Product(102,"Nuts");

Product p3=new Product(103,"Nails");

}
37547
System.out.println("Count is "+Product.count); 

Choose the options correctly so that the output will be

Count is 1
Count is 3

Note: You can use same options multiple times

Your answer is correct. 37547


The correct answer is:

Observe the below code

public class Product


{

int productId;

String productName;

static int count = 0;

public Product(int pid,String name){

productId = pid;

productName=name; 
https://accenturelearning.tekstac.com/mod/quiz/review.php?attempt=67961&cmid=1214#question-67961-4 2/5
9/12/23, 9:22 PM Test your understanding - static (copy): Attempt review

count++;
}

public static void main(String arg[]){

Product p1=new Product(101,"Screws");


[System.out.println("Count is "+Product.count);]
Product p2=new Product(102,"Nuts");

Product p3=new Product(103,"Nails");


[System.out.println("Count is "+Product.count);]
}
}
Choose the options correctly so that the output will be
Count is 1

37547
Count is 3

Note: You can use same options multiple times

Question 3
Correct

Mark 1.00 out of 1.00

Choose the correct option :

public class Flight{


int flightId;

static int noOfSeats;


37547
public static void display(){

System.out.println("No of seats "+noOfSeats); 

37547
Non static members cannot be accessed from static methods. If we want to access non static members from a static method it is
possible by creating an object. Hence, only "noOfSeats" can be accessed, not "flightId".

The correct answer is:


Choose the correct option :

public class Flight{

int flightId;
static int noOfSeats;

public static void display(){

[System.out.println("No of seats "+noOfSeats);]

}
}


https://accenturelearning.tekstac.com/mod/quiz/review.php?attempt=67961&cmid=1214#question-67961-4 3/5
9/12/23, 9:22 PM Test your understanding - static (copy): Attempt review

Question 4
Partially correct

Mark 0.33 out of 1.00

Observe the code :


public class Employee {
String name;
static int employeeCount;

//Line 1
}
Which of the following code can be included in Line 1?

Select one or more:


a.
public void display(){
System.out.println("Employee Name"+name);
}
37547
b. 
public static void display(){

System.out.println("Employee count "+employeeCount);

c.
public static void display() {
System.out.println("Employee Name"+name);

37547
}

d.
public void display(){

System.out.println("Employee count "+employeeCount);


}

From a static method, we can access only static members. Non static members cannot be accessed from static methods.

However, from a non static method, we can access both static and non static members.

You have correctly selected 1.


The correct answers are:
public static void display(){ 37547
System.out.println("Employee count "+employeeCount);
},
public void display(){
System.out.println("Employee count "+employeeCount);
},
public void display(){
System.out.println("Employee Name"+name);
}


https://accenturelearning.tekstac.com/mod/quiz/review.php?attempt=67961&cmid=1214#question-67961-4 4/5
9/12/23, 9:22 PM Test your understanding - static (copy): Attempt review

Question 5
Correct

Mark 1.00 out of 1.00

For the below code, what are the valid ways to invoke display method in the main method.
public class Test {
public static void display(){
}

}
public class Main {
public static void main(String a[]){
//Invoke the display method
}
}

Select one or more:


a. Test.display(); 37547
b. new Test().display();

c. display();

Static method can be invoked either by using the object instance or using the class name.
The correct answers are: Test.display();, new Test().display();

◄ Static 37547
Jump to...

Wrapper Scanner ►

37547


https://accenturelearning.tekstac.com/mod/quiz/review.php?attempt=67961&cmid=1214#question-67961-4 5/5

You might also like