-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathQandA.java
More file actions
43 lines (33 loc) · 1.01 KB
/
QandA.java
File metadata and controls
43 lines (33 loc) · 1.01 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
//Question 5: Design a program in java that identifies answer to ......
import java.util.Scanner;
public class QandA {
static{
System.out.println("This is written within static block");
}
{
System.out.println("This is written within instance block");
}
Scanner s = new Scanner(System.in);
public void Q1()
{
String q1 = s.nextLine();
System.out.println("A Static Block");
}
public void Q2()
{
String q2 = s.nextLine();
System.out.println("A Constructor: No. of times an object is called." +
"A Static Block: Only Once.");
}
public void Q3(){
String q3 = s.nextLine();
System.out.println("No." +
"This is because all the static members does not share the same copy of non static members.");
}
public static void main(String[] args) {
QandA obj = new QandA();
obj.Q1();
obj.Q2();
obj.Q3();
}
}