04 2015 档案
摘要:As usual, constructors are different from other kinds of methods. This is also true when polymorphism is involved. Even though constructors are not po...
阅读全文
摘要:看不懂 1 import java.util.*; 2 3 class Value { 4 int i; 5 6 public Value(int i) { 7 this.i = i; 8 } 9 }10 11 public class FinalData...
阅读全文
摘要:Create a simple class. Inside a second class, define a reference to an object ofthe first class. Use lazy initialization to instantiate this object. 1...
阅读全文
摘要:If you want the references initialized,you can do it: 1.At the point the objects are defined.This means that they'll always be initialized before the...
阅读全文
摘要:1 class A { 2 } 3 4 public class NewVarArgs { 5 6 static void printArray(Object... args) { 7 for (Object obj : args) { 8 Sy...
阅读全文
摘要:1 public class ArrayOfPrimitives { 2 3 public static void main(String[]args){ 4 int[]a1={1,2,3,4,5}; 5 int[]a2; 6 a2=a1;...
阅读全文
摘要:Create a class with a String field that is initialized at the point ofdefinition, and another one that is initialized by the constructor. What isthe d...
阅读全文
摘要:The this keyword is also useful for passing the current object to another method: 1 class Person { 2 public void eat(Apple apple) { 3 Appl...
阅读全文
摘要:1 public class Leaf { 2 3 int i = 0; 4 5 Leaf inceament() { 6 i++; 7 return this; 8 } 9 10 void print() {11 ...
阅读全文
摘要:题目A vampire number has an even number of digits and is formed by multiplying apair of numbers containing half the number of digits of the result. Thed...
阅读全文
摘要:1 import java.util.Scanner; 2 3 public class Fibonacci { 4 5 int fibo(int n) { 6 switch (n) { 7 case 1: 8 return 1;...
阅读全文
摘要:1 package java_test; 2 3 public class labelWhile { 4 5 public static void main(String[] args) { 6 int i = 0; 7 outer: while (tr...
阅读全文
摘要:1 package java_test; 2 3 public class LabeledFor { 4 5 public static void main(String[]args){ 6 int i=0; 7 outer: //Cannot have...
阅读全文
摘要:1 public class primeTest { 2 3 public static void main(String[] args) { 4 5 int i, j; 6 for (i = 3; i < 100; i++) { 7 ...
阅读全文
摘要:1 //THINGING IN JAVA P123 2 3 package java_test; 4 5 //Tests all the operators on all the primitive data types: 6 //to show which ones accept...
阅读全文
摘要:1 package exercise; 2 3 class Tank 4 { 5 int level; 6 } 7 8 public class Assignment{ 9 public static void main(String[]args){10 Tan...
阅读全文
摘要:if语句应写在某个代码块,或者方法中,否则实例化后,无法执行。所以eclipse纠错系统认为你少了一个大括号
阅读全文