【安博培训笔记】Java1 Java面向对象_PPT练习20130920
2013-09-21 10:03
656 查看
package com.ambow.java20130917; public class Student { private String name; private int age; private int banji; private String love; public Student(String name) { super(); this.name = name; } public Student(String name, int age, int banji) { super(); this.name = name; this.age = age; this.banji = banji; } public Student(String name, int age, int banji, String love) { super(); this.name = name; this.age = age; this.banji = banji; this.love = love; } /** * @return the name */ public String getName() { return name; } /** * @param name the name to set */ public void setName(String name) { this.name = name; } /** * @return the age */ public int getAge() { return age; } /** * @param age the age to set */ public void setAge(int age) { this.age = age; } /** * @return the banji */ public int getBanji() { return banji; } /** * @param banji the banji to set */ public void setBanji(int banji) { this.banji = banji; } /** * @return the love */ public String getLove() { return love; } /** * @param love the love to set */ public void setLove(String love) { this.love = love; } public void display() { System.out.println(name+" "+this.age+" "+banji+" "+this.love); } }
package com.ambow.java20130917;public class Sample {public static void main(String[ ] args) { Child c = new Child(); c.method(); }}
package com.ambow.java20130917; public class TeacherTest { public static void main(String[] args){ JavaTeacher jt=new JavaTeacher("李飞","计算机系"); jt.introduction(); jt.giveLesson(); NetTeacher nt=new NetTeacher("王刚","计算机系"); nt.introduction(); nt.giveLesson(); } }
package com.ambow.java20130917; public class Child extends Base { public Child(){ super("Child1"); name="Child2"; } }
package com.ambow.java20130917; public class Animal { public void eat() { System.out.println("eat"); } public void sleep() { System.out.println("sleep"); } }
package com.ambow.java20130917; public class StudentTest { public static void main(String[] args) { Student student = new Student("付仕华", 22, 02, "睡觉"); student.display(); Student student2 = new Student("付仕华"); student2.display(); } }
package com.ambow.java20130917; public class Teacher { private String name; // 教师姓名 private String dept; // 所在系部 public Teacher(String myName, String myDept) { name = myName; dept = myDept; } public void giveLesson(){ System.out.println("知识点讲解"); System.out.println("课堂总结"); } public void introduction() { System.out.println("大家好!我是"+ dept + "的" + name + "。"); } }
package com.ambow.java20130917; public class AnimalTiger extends Animal{ public void eat() { System.out.println("老虎吃肉"); } }
package com.ambow.java20130917; public class Base { public String name; public Base(){ name = "Base"; } public Base(String pName){ name = pName; } public void method(){ System.out.println(name); } }
package com.ambow.java20130917; public class Book { private String title; private int pageNum; public Book(String a,int b){ setTitle(a); if(b<=100) setPageNum(100); else setPageNum(b); } public int getPageNum() { return pageNum; } public void setPageNum(int pageNum) { if (pageNum <=100) this.pageNum = 100; else this.pageNum = pageNum; } public String getTitle() { return title; } public void setTitle(String title) { this.title = title; } public void display() { System.out.println(this.title+" "+this.pageNum); } public static void main(String[] args) { Book b = new Book("红豆",50); b.setPageNum(1000); b.display(); } }
package com.ambow.java20130917; public class Book1 { private String title; private int pageNum; private String type; public Book1(String title, int pageNum) { super(); this.title = title; this.pageNum = pageNum; this.type = "计算机"; } public Book1(String title, int pageNum, String type) { super(); this.title = title; this.pageNum = pageNum; this.type = type; } /** * @return the title */ public String getTitle() { return title; } /** * @param title the title to set */ public void setTitle(String title) { this.title = title; } /** * @return the pageNum */ public int getPageNum() { return pageNum; } /** * @param pageNum the pageNum to set */ public void setPageNum(int pageNum) { this.pageNum = pageNum; } /** * @return the type */ public String getType() { return type; } /** * @param type the type to set */ public void setType(String type) { this.type = type; } public void display() { System.out.println("title="+getTitle()+" pageNum="+getPageNum() +" type="+getType()); } }
package com.ambow.java20130917; public class BookTest { public static void main(String[] args) { Book book = new Book("红豆", 50); book.display(); } }
package com.ambow.java20130917; public class Book1Test { public static void main(String[] args) { Book1 book1 = new Book1("浪潮之巅", 100); book1.display(); Book1 book12 = new Book1("红豆", 10, "心灵驿站"); book12.display(); } }
package com.ambow.java20130917; public class table { private String color; private double length; private double width; private double height; public table(String color, double length, double width, double height) { super(); this.color = color; this.length = length; this.width = width; this.height = height; } /** * @return the color */ public String getColor() { return color; } /** * @param color the color to set */ public void setColor(String color) { this.color = color; } /** * @return the length */ public double getLength() { return length; } /** * @param length the length to set */ public void setLength(double length) { this.length = length; } /** * @return the width */ public double getWidth() { return width; } /** * @param width the width to set */ public void setWidth(double width) { this.width = width; } /** * @return the height */ public double getHeight() { return height; } /** * @param height the height to set */ public void setHeight(double height) { this.height = height; } public void display() { System.out.println("color="+getColor()+" length="+getLength()+" width="+ getWidth()+" height="+getHeight()); } public static void main(String[] args) { table table = new table("绿",1,1,1); table.display(); } }
package com.ambow.java20130917; public class Student { private String name; private int age; private int banji; private String love; public Student(String name) { super(); this.name = name; } public Student(String name, int age, int banji) { super(); this.name = name; this.age = age; this.banji = banji; } public Student(String name, int age, int banji, String love) { super(); this.name = name; this.age = age; this.banji = banji; this.love = love; } /** * @return the name */ public String getName() { return name; } /** * @param name the name to set */ public void setName(String name) { this.name = name; } /** * @return the age */ public int getAge() { return age; } /** * @param age the age to set */ public void setAge(int age) { this.age = age; } /** * @return the banji */ public int getBanji() { return banji; } /** * @param banji the banji to set */ public void setBanji(int banji) { this.banji = banji; } /** * @return the love */ public String getLove() { return love; } /** * @param love the love to set */ public void setLove(String love) { this.love = love; } public void display() { System.out.println(name+" "+this.age+" "+banji+" "+this.love); } }
package com.ambow.java20130917; public class RectangleTest { public static void main(String[] args) { Rectangle rectangle = new Rectangle(1,1); rectangle.display(); } }
package com.ambow.java20130917; public class NetTeacher extends Teacher { public NetTeacher(String myName, String myDept) { super(myName, myDept); } public void giveLesson() { System.out.println("启动 Visual Studio 2005"); super.giveLesson(); } }
package com.ambow.java20130917; public class JavaTeacher extends Teacher { public JavaTeacher (String myName, String myDept) { super(myName, myDept); } public void giveLesson(){ System.out.println("启动 MyEclipse 6.0"); super.giveLesson(); } }
package com.ambow.java20130917; public class HomeworkTest { public static void main(String[] args) { Homework hs = new HomeworkStudent(); Homework ht = new HomeworkTeacher(); hs.collectHomework(); ht.collectHomework(); } }
package com.ambow.java20130917; public interface Homework { public void collectHomework(); }
package com.ambow.java20130917; public class HomeworkTeacher implements Homework { @Override public void collectHomework() { // TODO Auto-generated method stub System.out.println("老师收作业"); } }
package com.ambow.java20130917; public class HomeworkStudent implements Homework { @Override public void collectHomework() { // TODO Auto-generated method stub System.out.println("学生收作业"); } }
package com.ambow.java20130917; public class AnimalTest { public static void main(String[] args) { AnimalRabbit animalRabbit = new AnimalRabbit(); animalRabbit.eat(); animalRabbit.sleep(); AnimalTiger animalTiger = new AnimalTiger(); animalTiger.eat(); animalTiger.sleep(); } }
package com.ambow.java20130917; public class AnimalRabbit extends Animal { public void eat() { System.out.println("兔子吃草"); } }
相关文章推荐
- 【安博培训笔记】Java2 数组、字符串、常用工具类_课下作业1_20130920
- 【安博培训笔记】Java2 数组、字符串、常用工具类_课下作业2_20130920
- 【安博培训笔记】Java 基础_下课作业1_20130920
- 【安博培训笔记】Java 基础_下课作业2_20130920
- java学习笔记《java面向对象编程》——面向对象开发方法概述
- JAVA学习笔记(初级)--面向对象基础
- Java面向对象笔记(六)static关键字
- Java基础笔记整理---【06】面向对象程序设计-封装
- 【学习笔记09】java面向对象-final、抽象类
- 黑马程序员---java学习笔记之面向对象知识点
- Java学习笔记(1)面向对象
- Java面向对象笔记(二)
- JAVA面向对象练习03
- java面向对象笔记(五分钟秒懂)
- 【学习笔记18】java面向对象-运行时异常、编译时异常
- 学习笔记4—Java基础3_面向对象上b
- JAVA笔记六(21-24 对象转型(多态性)、面向对象应用、抽象类和抽象函数)
- 黑马程序员_java面向对象学习笔记
- java面向对象练习08(游戏角色)
- Java学习笔记16(面向对象九:补充内容)