Created
May 27, 2014 02:02
-
-
Save siritori/56b079b7cc482d3229da to your computer and use it in GitHub Desktop.
情報科学I
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Disp | |
{ | |
void display() { | |
System.out.println("No argument"); | |
} | |
void display(String s) { | |
System.out.println(s); | |
} | |
void display(String s, int n) { | |
System.out.println(s + ", " + n); | |
} | |
} | |
public class CreateClass | |
{ | |
public static void main(String args[]) { | |
Disp obj = new Disp(); | |
obj.display(); | |
obj.display("Hello"); | |
obj.display("Hi", 100); | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Mine | |
{ | |
private int no; | |
private String name; | |
void setData(int no, String name) { | |
this.no = no; | |
this.name = name; | |
} | |
void print() { | |
System.out.println(no); | |
System.out.println(name); | |
} | |
void formalPrint() { | |
System.out.println("No : " + no); | |
System.out.println("Name : " + name); | |
} | |
} | |
public class Person | |
{ | |
public static void main(String args[]) { | |
Mine p = new Mine(); | |
p.setData(1, "Tanaka"); | |
p.print(); | |
System.out.println("----------"); | |
p.formalPrint(); | |
} | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class Employee | |
{ | |
private int no; | |
private String name; | |
Employee() { | |
this.no = 0; | |
this.name = "No name"; | |
} | |
Employee(int no, String name) { | |
this.no = no; | |
this.name = name; | |
} | |
static void description() { | |
System.out.println("This is Program printing Emplyee data."); | |
System.out.println("Have fun!"); | |
} | |
void print() { | |
System.out.println("No : " + this.no); | |
System.out.println("Name : " + this.name); | |
} | |
void changeData(int no, String name) { | |
this.no = no; | |
this.name = name; | |
} | |
} | |
public class PrintEmp | |
{ | |
public static void main(String args[]) { | |
Employee.description(); | |
System.out.println("----------------"); | |
Employee emp1 = new Employee(1, "Tanaka"); | |
emp1.print(); | |
System.out.println("----------------"); | |
Employee emp2 = new Employee(); | |
emp2.print(); | |
System.out.println("----------------"); | |
emp2.changeData(5, "Yamada"); | |
emp2.print(); | |
System.out.println("----------------"); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment