0% found this document useful (0 votes)
195 views6 pages

Test Your Understanding - Static (Copy) - Attempt Review

The document summarizes the results of a quiz on static methods and variables in Java programming. The quiz contained 5 multiple choice questions testing understanding of when static and non-static members can be accessed and how static methods can be invoked. The student scored 4 out of 5 points with an overall grade of 80%. Feedback indicated they passed by securing over 80% and congratulated them.

Uploaded by

19K41A0 450
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
0% found this document useful (0 votes)
195 views6 pages

Test Your Understanding - Static (Copy) - Attempt Review

The document summarizes the results of a quiz on static methods and variables in Java programming. The quiz contained 5 multiple choice questions testing understanding of when static and non-static members can be accessed and how static methods can be invoked. The student scored 4 out of 5 points with an overall grade of 80%. Feedback indicated they passed by securing over 80% and congratulated them.

Uploaded by

19K41A0 450
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/ 6

11/14/23, 3:54 PM Test your understanding - static (copy): Attempt review


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

Quiz review
Started on Sunday, 12 November 2023, 5:39 PM
State Finished
Completed on Sunday, 12 November 2023, 5:44 PM
Time taken 5 mins 40 secs
Marks 4.00/5.00
Grade 80.00 out of 100.00
Feedback
Congratulations!!! You have passed by securing more than 80%

42763

42763

42763

https://accenturelearning.tekstac.com/mod/quiz/review.php?attempt=685301&cmid=1214 1/6
11/14/23, 3:54 PM Test your understanding - static (copy): Attempt review

Question 1
Correct

Mark 1.00 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 static void display(){
System.out.println("Employee count "+employeeCount);

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

c. 
public void display(){

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

42763
}

d.
public static void display() {

System.out.println("Employee Name"+name);

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.

The correct answers are:


public static void display(){

},
42763
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=685301&cmid=1214 2/6
11/14/23, 3:54 PM Test your understanding - static (copy): Attempt review

Question 2
Correct

Mark 1.00 out of 1.00

Choose the correct option :

public class Flight{


int flightId;
static int noOfSeats;

public static void display(){

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

}
}

42763
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(){

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

42763

https://accenturelearning.tekstac.com/mod/quiz/review.php?attempt=685301&cmid=1214 3/6
11/14/23, 3:54 PM Test your understanding - static (copy): Attempt review

Question 3
Partially correct

Mark 0.50 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;

42763
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");

42763
System.out.println("Count is "+(1+p2.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 partially correct. 42763


You have correctly selected 1.
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;

https://accenturelearning.tekstac.com/mod/quiz/review.php?attempt=685301&cmid=1214 4/6
11/14/23, 3:54 PM Test your understanding - static (copy): Attempt review
productName=name;
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

42763
Count is 1
Count is 3

Note: You can use same options multiple times

Question 4
Correct

Mark 1.00 out of 1.00

Match the following :

non static method 42763


Can access both static and non static members 

static method
Can access static members only 

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

42763

https://accenturelearning.tekstac.com/mod/quiz/review.php?attempt=685301&cmid=1214 5/6
11/14/23, 3:54 PM Test your understanding - static (copy): Attempt review

Question 5
Partially correct

Mark 0.50 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(); 42763
b. new Test().display();

c. display();

Static method can be invoked either by using the object instance or using the class name.

You have correctly selected 1.


The correct answers are: Test.display();, new Test().display();

◄ Static
42763
Jump to...

Wrapper Scanner ►

42763

https://accenturelearning.tekstac.com/mod/quiz/review.php?attempt=685301&cmid=1214 6/6

You might also like