标签:
1
int score =61;
boolean is = score > 60;
Person per =new Person();
new Person().tell();
class Person
{
int age;
public Person(int age)
{
this();
this.age=age;
}
public Person()
{
System.out.println("Empty");
}
}
String str = new String ("Hello");
String str = "Hello";
String str = "Hello";
String str1 = new String ("Hello");
String str2 = "Hello";
System.out.println(str==str1);
System.out.println(str.equals(str1));
System.out.println(str==str2);
String name = "Good";
char data[]=name.toCharArray();
String name = "Good";
System.out.println(name.charAt(0));
String name = "Good";
byte[] bytes=name.getBytes();
String name = "Good";
System.out.println(name.indexOf(‘o‘));
System.out.println(name.indexOf(‘a‘));
System.out.println(name.indexOf("oo"));
String str ="Helloooo";
for(int i = 0;i<100;i++)
{
str+=i;
}
System.out.println(str);
StringBuffer sb = new StringBuffer();
sb.append(str);
for(int i = 0;i<100;i++)
{
sb.append(i);
}
System.out.println(sb);
B bb = new B();
A a =bb;
a.tell1();
a.tell2();
A a =new B();
B b =(B)a ;
b.tell1();
b.tell2();
b.tell3();
package Test1;
class A
{
public void tell1()
{
System.out.println("A----tell1");
}
}
class B extends A
{
public void tell2()
{
System.out.println("B----tell2");
}
}
class C extends A{
public void tell3()
{
System.out.println("C----tell3");
}
}
public class Test2 {
public static void main(String[] args){
say(new B());
say(new C());
}
public static void say(A a)
{
a.tell1();
}
}
public class Test2 {
public static void main(String[] args){
say(new B());
say(new C());
}
public static void say(B b)
{
b.tell1();
}
public static void say(C c)
{
c.tell1();
}
}
A a =new A();
System.out.println(a instanceof A);
System.out.println(a instanceof B);
A a1 = new B();
System.out.println(a1 instanceof A);
System.out.println(a1 instanceof B);
package Test1;
interface USB
{
void start();
void stop();
}
class C {
public static void Work(USB usb)
{
usb.start();
System.out.println("Working");
usb.stop();
}
}
class USBDisk implements USB{
public void start() {
System.out.println("USB Start");
}
public void stop() {
System.out.println("USB Stop");
}
}
class Printer implements USB{
public void start() {
System.out.println("Printer Start");
}
public void stop() {
System.out.println("Printer Stop");
}
}
public class Test2 {
public static void main(String[] args){
C.Work(new USBDisk());
C.Work(new Printer());
}
}
System.err.println("Hello World");
public class Test2 {
public static void main(String[] args) throws Exception {
try {
throw new Exception("Hello");
} catch (Exception e) {
System.out.println(e);
}
}
public static void tell(int a , int b)throws ArithmeticException{
System.out.println(a/b);
}
}
class Exc extends Exception{
public Exc(String msg){
super(msg);
}
}
public class Test2 {
public static void main(String[] args) throws Exception {
try {
throw new Exc("Good");
} catch (Exc e) {
System.out.println(e);
}
}
}
标签:
原文地址:http://www.cnblogs.com/GoFly/p/4724646.html