File tree Expand file tree Collapse file tree 8 files changed +117
-7
lines changed Expand file tree Collapse file tree 8 files changed +117
-7
lines changed Original file line number Diff line number Diff line change
1
+ public class Car {
2
+ String make = "Ford" ;
3
+ String model = "Mustang" ;
4
+ int year = 2020 ;
5
+ String color = "black" ;
6
+ double price = 50000.00 ;
7
+
8
+ void drive (){
9
+ System .out .println ("You drive the car" );
10
+ }
11
+ void brake (){
12
+ System .out .println ("You step on the brakes" );
13
+ }
14
+
15
+ }
Original file line number Diff line number Diff line change
1
+
2
+ public class Final {
3
+ public static void main (String [] args ){
4
+ final double PI = 3.14159 ;
5
+ System .out .println (PI );
6
+ return ;
7
+ }
8
+ }
Original file line number Diff line number Diff line change
1
+ public class Human {
2
+ String name ;
3
+ int age ;
4
+ double weight ;
5
+ Human (String name , int age , double weight ){
6
+ this .name = name ;
7
+ this .age = age ;
8
+ this .weight = weight ;
9
+ }
10
+
11
+ void eat (){
12
+ System .out .println (this .name + " eating" );
13
+ }
14
+
15
+ void drink (){
16
+ System .out .println (this .name + " drinking" );
17
+ }
18
+ }
Original file line number Diff line number Diff line change 1
1
public class Main {
2
2
public static void main (String [] args ){
3
- String name = "Bro" ;
4
- hello (name );
5
- return ;
6
- }
7
-
8
- static void hello (String name ){
9
- System .out .println ("hello " + name );
3
+ Human human = new Human ("Ranuga" , 15 , 50.0 );
4
+ Human human2 = new Human ("Disansa" , 15 , 50.0 );
10
5
return ;
11
6
}
12
7
}
Original file line number Diff line number Diff line change
1
+ public class Methods {
2
+ public static void main (String [] args ){
3
+ int x = 3 ;
4
+ int y = 4 ;
5
+ return ;
6
+ }
7
+
8
+ static int add (int num1 , int num2 ){
9
+ return num1 + num2 ;
10
+ }
11
+ // public static void main(String[] args){
12
+ // String name = "Bro";
13
+ // int age = 21;
14
+ // hello(name, age);
15
+ // return;
16
+ // }
17
+ //
18
+ // static void hello(String name, int age){
19
+ // System.out.println("hello " + name + age);
20
+ // return;
21
+ // }
22
+ }
Original file line number Diff line number Diff line change
1
+ public class OOP {
2
+ public static void main (String [] args ){
3
+ Car myCar = new Car ();
4
+ Car myCar2 = new Car ();
5
+
6
+ System .out .println (myCar .model );
7
+ System .out .println (myCar .make );
8
+
9
+ myCar .drive ();
10
+ myCar .brake ();
11
+ return ;
12
+ }
13
+ }
Original file line number Diff line number Diff line change
1
+ public class OverLoading {
2
+ public static void main (String [] args ){
3
+ return ;
4
+ }
5
+
6
+ static int add (int a , int b ){
7
+ return a + b ;
8
+ }
9
+
10
+ static int add (int a , int b , int c ){
11
+ return a +b +c ;
12
+ }
13
+ }
Original file line number Diff line number Diff line change
1
+
2
+ public class PrintF {
3
+ public static void main (String [] args ){
4
+ // System.out.printf("This is a format string %d", 123);
5
+ boolean myBoolean = true ;
6
+ char myChar = '@' ;
7
+ String myString = "Bro" ;
8
+ int myInt = 50 ;
9
+ double myDouble = 1000 ;
10
+
11
+ System .out .printf ("%b" , myBoolean );
12
+ System .out .printf ("%c" , myChar );
13
+ System .out .printf ("%s" , myString );
14
+ System .out .printf ("%d" , myInt );
15
+ System .out .printf ("%f" , myDouble );
16
+
17
+ System .out .printf ("Hello %10s" , myString );
18
+ System .out .printf ("Hello %-10s" , myString );
19
+
20
+ System .out .printf ("%.2f" , myDouble );
21
+
22
+
23
+ return ;
24
+ }
25
+ }
26
+
You can’t perform that action at this time.
0 commit comments