Inheritance, composition, and so on:
Attachment can download the code, js directly run ie the, java can run the jdk compiler can also be run ide.
See the code - java的,呵呵java programmer code not to watch this拍砖[too easy, in order to study js]
/ / Oh do not show that you are familiar with the future of java
public class Object (
public static void main (String [] args) (
Classes classes = new Classes (new Student [] (new Student ( "kite", 18), new Student ( "tom", 19)));
System.out.println (classes.showClassInfo ());
)
)
class Student (
private String name;
private int age;
Student (String name, int age) (
this.age = age;
this.name = name;
)
public String toString () (
return "name is" + name + "age" + age + "\ n";
)
)
class Classes (
private Student [] students;
Classes (Student [] students) (
this.students = students;
)
public String showClassInfo () (
StringBuilder builder = new StringBuilder ();
for (Student s: students) (
builder.append (s.toString ());
)
return builder.toString ();
)
)
/ / Writing a js similar to the following code, save it as a direct IE to open xx.html
See code
<script>
/ / Definition of the class js [Ha ha is not a category, that is, examples Function] constructor function Student (name, age) (
this.name = name;
this.age = age;
)
/ / Give Student increasing function toString
Student.prototype.toString = function () (
return "name is" + this.name + "age" + this.age + "\ n";
)
/ / Definition of the class js [not oh] constructor function Classes (students) (
this.students = students;
)
/ / Increase the Classes function showClassInfo [Think java anonymous methods, consider the C function pointer]
Classes.prototype.showClassInfo = function () (
var str = "";
for (var i = 0; i <this.students.length; i + +)
str + = this.students [i]. toString ();
return str;
)
/ / Easy as the main method of java in fact, different interpretation of a compiler are var myClasses = new Classes ([new Student ( "kite", 18), new Student ( "tom", 19)]);
alert (myClasses.showClassInfo ());
</ script>







