Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit ac24aa3

Browse files
committed
constructors in java
1 parent b50fe3b commit ac24aa3

File tree

3 files changed

+43
-7
lines changed

3 files changed

+43
-7
lines changed

.idea/codeStyles/codeStyleConfig.xml

Lines changed: 5 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

.idea/vcs.xml

Lines changed: 6 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/Main.java

Lines changed: 32 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,40 @@
1+
class Shape {
2+
String colour;
3+
double area;
4+
Shape(String colour) {
5+
this.colour = colour;
6+
}
7+
Shape(String colour, double area){
8+
this.colour=colour;
9+
this.area=area;
10+
}
111

12+
Shape(Shape s1){
13+
this.colour=s1.colour;
14+
this.area=s1.area;
15+
}
216

3-
class Student{
4-
String name;
17+
void findArea(){
18+
19+
}
520

6-
}
721

22+
}
823

924
public class Main {
1025
public static void main(String[] args) {
11-
Student s1=new Student();
12-
s1.name="Binod";
13-
System.out.println(s1.name);
26+
Shape s1 = new Shape("red", 2.3);
27+
Shape s2=new Shape(s1);
28+
System.out.println("properties of s1");
29+
System.out.println(s1.colour);
30+
System.out.println(s1.area);
31+
System.out.println("\n");
32+
System.out.println("properties of s2");
33+
System.out.println(s2.colour);
34+
System.out.println(s2.area);
1435
}
15-
}
36+
}
37+
//primitives data types
38+
//int, double, String, float, long , short, byte, boolean
39+
//wrapper classes
40+
//Int, Double, String, Float, Long,

0 commit comments

Comments
 (0)