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
[Link] 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");
[Link]("Count is "+[Link]);
Product p2=new Product(102,"Nuts");
Product p3=new Product(103,"Nails");
}
37547
[Link]("Count is "+[Link]);
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;
[Link] 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");
[[Link]("Count is "+[Link]);]
Product p2=new Product(102,"Nuts");
Product p3=new Product(103,"Nails");
[[Link]("Count is "+[Link]);]
}
}
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(){
[Link]("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(){
[[Link]("No of seats "+noOfSeats);]
}
}
[Link] 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(){
[Link]("Employee Name"+name);
}
37547
b.
public static void display(){
[Link]("Employee count "+employeeCount);
c.
public static void display() {
[Link]("Employee Name"+name);
37547
}
d.
public void display(){
[Link]("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
[Link]("Employee count "+employeeCount);
},
public void display(){
[Link]("Employee count "+employeeCount);
},
public void display(){
[Link]("Employee Name"+name);
}
[Link] 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. [Link](); 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: [Link]();, new Test().display();
◄ Static 37547
Jump to...
Wrapper Scanner ►
37547
[Link] 5/5