Skip to content

Commit a011445

Browse files
authored
Merge pull request #17 from yashpatel08/main
Add files via upload
2 parents d21efa6 + 202594c commit a011445

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

50 files changed

+1290
-0
lines changed

A.java

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
// private constructor//
2+
3+
class A
4+
{
5+
int a; double b; String c;
6+
private A()
7+
{
8+
a=15;
9+
b=15.45;
10+
c="yash";
11+
System.out.println(a+" "+b+" "+c);
12+
}
13+
14+
public static void main(String[] args) //if we can write this main method in other class (like class b)then it eill not access the value or it will show error
15+
{
16+
A r=new A();
17+
18+
}
19+
20+
}

B.java

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
//default constructor
2+
class A
3+
{
4+
int a; String b; boolean c;
5+
A()// if we comment out this constructor then all value will be given by compiler and it will be default value because it will create a default constructor
6+
{
7+
a=100; b="yash"; c=true;
8+
}
9+
void Disp()
10+
{
11+
System.out.println(a+" "+b+" "+c);
12+
}
13+
}
14+
class B
15+
{
16+
public static void main(String[] args) {
17+
18+
A r=new A();
19+
20+
r.Disp();
21+
22+
}
23+
24+
}

Customer.java

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
2+
public class Customer {
3+
4+
public void stop() {
5+
}
6+
7+
public void start() {
8+
}
9+
10+
}

array.java

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
public class array {
2+
3+
public static void main(String[] args) {
4+
5+
int a[]={10,20,30,40,50};
6+
System.out.println(a[2]);
7+
System.out.println(a[4]);
8+
9+
System.out.print("by for each loop ");//example of for each loop for printing array
10+
11+
for (int b : a) {
12+
13+
System.out.print(b+" ");
14+
15+
}
16+
}
17+
18+
}

array2.java

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
import java.util.Scanner;
2+
3+
public class array2 {
4+
5+
public static void main(String[] args) {
6+
7+
int a[]=new int[5];
8+
System.out.print("enter the array elements");
9+
Scanner p=new Scanner(System.in);
10+
for (int i = 0; i < 5; i++) {
11+
12+
a[i]=p.nextInt();
13+
}
14+
System.out.print("\n array elements are\n");
15+
for (int b : a) {
16+
17+
System.out.println(b+" ");
18+
19+
}
20+
21+
}
22+
23+
}

constructor_ex.java

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
// constructor is use initialise the variable or value of property it is represent by class name e.g---constructor_ex
2+
class constructor_ex
3+
{
4+
int a; String name;
5+
constructor_ex() // if we comment this constructor part then program will also run because it will create default constructor
6+
{
7+
a=0; name=null ;
8+
9+
}
10+
void show()
11+
{
12+
System.out.println(a+" "+name);
13+
}
14+
}
15+
class b
16+
{
17+
public static void main(String[] args)
18+
{
19+
constructor_ex ref=new constructor_ex();
20+
ref.show();
21+
}
22+
}

copy_constructor.java

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
//here we are copy from simple constructor
2+
class d {
3+
4+
int b;
5+
String c;
6+
7+
d() //this is constructor
8+
{
9+
b = 200;
10+
c = "yash";
11+
System.out.println(b + " " + c);
12+
}
13+
14+
d(d ref) // this is copy constructor by using this we can see that value of a constructor is copy by passing reference as parameter
15+
{
16+
b = ref.b;
17+
c = ref.c;
18+
System.out.println(b + " " + c);
19+
}
20+
21+
}
22+
23+
class copy_constructor {
24+
25+
public static void main(String[] args) {
26+
27+
d r = new d();
28+
d r2 = new d(r);
29+
30+
}
31+
32+
}

copy_constructor2.java

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
// here we copy parameterised constructor
2+
class e
3+
{
4+
int x,y;
5+
6+
e(int u,int v)//parameterised
7+
{
8+
x=u;
9+
y=v;
10+
11+
}
12+
e(e ref) // this is copy constructor by using this we can see that value of a constructor is copy by passing reference as parameter
13+
{
14+
u = ref.u;
15+
v = ref.v;
16+
System.out.println(u + " " + v);
17+
}
18+
void dip()
19+
{
20+
System.out.println(x+ " " +y);
21+
}
22+
23+
}
24+
class copy_constructor2 {
25+
26+
public static void main(String[] args)
27+
{
28+
copy_constructor2 r=new copy_constructor2();
29+
r.dip();
30+
31+
}

example_class.java

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
public class example_class {
2+
3+
4+
int age=19;
5+
int weight=52;
6+
String colour="light";
7+
void eat()
8+
{
9+
System.out.println("i'm eating");
10+
}
11+
void sleep()
12+
{
13+
System.out.println("i'm sleeping");
14+
}
15+
16+
public static void main(String[] args)
17+
{
18+
example_class P=new example_class();
19+
System.out.println(P.age);
20+
System.out.println(P.weight);
21+
System.out.println(P.colour);
22+
23+
P.eat(); P.sleep();
24+
}
25+
26+
}

first.java

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
public class first {
2+
public static void main(String[] args) {
3+
4+
System.out.print("java begins");
5+
6+
}
7+
8+
}

0 commit comments

Comments
 (0)