学习 java langspec-3.0. 规范后的代码
来源:互联网 发布:java 依赖包 编辑:程序博客网 时间:2024/06/05 03:14
package com;
public interface gg {public void ss();}package com;public abstract class tt {public void ss(){}}package com;public class ww extends tt implements gg {}
package com;public class ww {static ww w=new ww();static {System.out.println("初始化");} public ww(){System.out.println("构造函数");}}package com.test;import com.ww;public class Client {/** * @param args */public static void main(String[] args) {// TODO Auto-generated method stubnew ww();}}
package com;public class ww {public interface aa {void dd();}}package com.test;import com.ww;public class Client implements ww.aa {/** * @param args */public static void main(String[] args) {// TODO Auto-generated method stub}public void dd() {// TODO Auto-generated method stub}}
package com;public class ww { publicww(){} protected static void ss() { } interface aa{void dd();}public static class ss implements aa{public void dd() {// TODO Auto-generated method stub}}}package com;public class Client {/** * @param args */public static void main(String[] args) {// TODO Auto-generated method stubww.ss s =new ww.ss();}}
package com;public class ww { publicww(){} protected static void ss() { } interface aa{void dd();}public class ss implements aa{public void dd() {// TODO Auto-generated method stub}}}package com;public class Client {/** * @param args */public static void main(String[] args) {// TODO Auto-generated method stubww w = new ww();ww.ss s = w.new ss();}}
package com;public class ww {{System.out.println("初始化");} public ww(){System.out.println("构造函数");}}package com.test;import com.ww;public class Client {/** * @param args */public static void main(String[] args) {// TODO Auto-generated method stubnew ww();}}
package com;public abstract class ww {static {System.out.println("类初始化");}{System.out.println("实例初始化");}public static void ss() {System.out.println("我是一个抽象类的静态方法");}public ww() {System.out.println("构造函数");}}package com.test;import com.ww;public class Client {/** * @param args */public static void main(String[] args) {// TODO Auto-generated method stubww.ss();}}
泛型的使用
- package com;
- public class WW<T> {
- T t;
- public T getT() {
- return t;
- }
- public void setT(T t) {
- this.t = t;
- }
- public T print() {
- System.out.println(t.toString());
- return t;
- }
- public static void main(String[] args) {
- WW<String> w = new WW<String>();
- w.setT("sss");
- w.print();
- }
- }
- package com.org;
- public interface gg<T>{
- public
- void ss(T t);
- }
- package com;
- import com.org.gg;
- public class WW<T> implements gg<T> {
- public void ss(T t) {
- }
- public static void main(String[] args) {
- }
- }
- package com.test2;
- public class TT {
- public TT(String s)
- {
- System.out.println("super Constructor");
- }
- }
- package com;
- import com.test2.TT;
- public class WW extends TT {
- public WW(String s) {
- super(s);
- // TODO Auto-generated constructor stub
- }
- public static void main(String[] args) {
- new WW("sss");
- }
- }
- package com.test2;
- public class TT {
- public TT()
- {
- System.out.println("super Constructor");
- }
- }
- package com;
- import com.test2.TT;
- public class WW extends TT {
- public static void main(String[] args) {
- new WW();
- }
- }
- package com.test2;
- public class TT {
- static {
- System.out.println("super static Initializer");
- }
- }
- package com;
- import com.test2.TT;
- public class WW extends TT {
- public static void main(String[] args) {
- new WW();
- }
- }
- package com.test2;
- public class tt {
- public void m1() {
- m2();
- }
- public void m2() {
- System.out.println("super m2");
- };
- }
- package com;
- import com.test2.tt;
- public class WW extends tt {
- public static void main(String[] args) {
- new WW().m1();
- }
- public void m2() {
- System.out.println("sub m2");
- }
- }
- package com.test2;
- public abstract class tt {
- {
- System.out.println("sss");
- }
- public void set()
- {
- }
- }
- package com;
- import com.test2.tt;
- public class WW extends tt {
- public static void main(String[] args) {
- new WW();
- }
- }
- package com;
- public class WW {
- int s = gets();
- public int gets() {
- System.out.println("gets");
- return 10;
- }
- public static void main(String[] args) {
- new WW();
- }
- }
- package com.org;
- public interface gg {
- public int s = 100000;
- }
- package com.test2;
- public class TT {
- public String s="100";
- }
- package com;
- import com.org.gg;
- import com.test2.TT;
- public class WW extends TT implements gg {
- public int s = 10;
- public static void main(String[] args) {
- WW w = new WW();
- TT t = w;
- gg g = w;
- System.out.println(t.s);
- System.out.println(w.s);
- System.out.println(g.s);
- }
- }
下面的程序为什么在编译时报错呢?
- package com.org;
- public interface gg {
- public int s = 100000;
- }
- package com.test2;
- public class TT {
- public String s="100";
- }
- package com;
- import com.org.gg;
- import com.test2.TT;
- public class WW extends TT implements gg {
- public void s()
- {
- System.out.println(s);
- }
- }
- package com.test2;
- public class TT {
- public int s=100;
- }
- package com;
- import com.test2.TT;
- public class WW extends TT {
- public int s = 10;
- public static void main(String[] args) {
- TT t = new WW();
- WW w = new WW();
- System.out.println(t.s);
- System.out.println(w.s);
- }
- }
import static的使用:
- package com.org;
- public interface gg {
- int s = 100000;
- }
- package com;
- import static com.org.gg.s;
- public class WW {
- public void s() {
- System.out.println(s);
- }
- public static void main(String[] args) {
- new WW().s();
- }
- }
- package com.test2;
- public class TT {
- public void ss(){
- System.out.println("super");
- }
- }
- package com;
- import com.test2.TT;
- public class WW extends TT {
- public static void main(String[] args) {
- WW w=new WW();
- w.ss();
- TT t=w;
- t.ss();
- }
- public void ss(){
- System.out.println("sub");
- }
- }
下面的这段代码编译出错
- package com.test2;
- public class TT {
- public void ss(){
- System.out.println("super");
- }
- }
- package com;
- import com.test2.TT;
- public class WW extends TT {
- public static void main(String[] args) {
- }
- protected void ss() {
- System.out.println("sub");
- }
- }
那下面的程序的输出会是什么呢?
- 学习 java langspec-3.0. 规范后的代码
- volatile Fields(langspec-3.0)
- java的代码规范
- 个人的Java代码规范
- java代码的一些规范
- JAVA的代码书写规范
- java 规范的代码结构
- java开发的代码规范
- 关于 Java 的代码规范
- java后端的代码规范
- 学习JAVA后写的第一段代码
- 开发规范: JAVA代码规范
- JAVA代码编写程序的基本规范
- Sun官方发布的Java代码规范
- JAVA代码编写程序的基本规范
- 一些比较好的java代码规范
- 公司制定的Java代码规范
- 公司制定的Java代码规范
- ASP.NET 菜单控件概述
- VS2005有 Platform SDK
- 用C#实现语音技术
- 不需公网IP架设OpenVPN
- 第一次来
- 学习 java langspec-3.0. 规范后的代码
- C#比较两时间大小
- 使用 Request.QueryString 接受参数时,跟编码有关的一些问题
- Asp.Net输出数据到EXCEL中
- 中间件菜鸟初识读书笔记
- ASP.NET 2.0 中的 Windows 身份验证
- FC7安装笔记
- 使用HttpWebRequest提交ASP.NET表单并保持Session和Cookie
- ASP.NET 加密类