標題:
物件導向基礎概念 (三)
[打印本頁]
作者:
周政輝
時間:
2018-10-20 13:42
標題:
物件導向基礎概念 (三)
定義一Dog類別, 包含建構子及兩個方法.
showProfile() 用來顯示基本資料, makeSound(int n) 用來發出聲音.
[attach]5075[/attach]
作者:
王駿愷
時間:
2018-10-20 15:03
public class Main {
public static void main(String[] args) {
// TODO 自動產生的方法 Stub
dog dog =new dog("憨憨",1,1.3,"紅棕色");
dog.ShowProfile();
dog.makesound(3);
}
}
複製代碼
public class dog {
String name;
int age;
double weight;
String color;
public void ShowProfile()
{
System.out.println(String.format("%s今年%d歲,體重%f公斤毛色%s",this.name,this.age,this.weight,this.color));
}
public void makesound(int n)
{
for(int i=0;i<n;i++)
{
System.out.print("汪~");
}
System.out.println();
}
dog(String name,int age,double weight,String color)
{
this.name=name;
this.age=age;
this.weight=weight;
this.color=color;
}
}
複製代碼
作者:
鄭楀諺
時間:
2018-10-20 15:03
本帖最後由 鄭楀諺 於 2018-10-20 15:05 編輯
package Morris;
public class Main {
public static void main(String[] args) {
// TODO 自動產生的方法 Stub
Dog dog =new Dog("Momo","blue",2,1.3);
dog.showProfile();
dog.makesound(3);
}
}
package Morris;
public class Dog {
String name;
String color;
int age;
double weight;
public void showProfile()
{
System.out.println(String.format("%s今年%d歲,體重%f公斤,毛色為%s", this.name,this.age,this.weight,this.color));
}
public void makesound(int n)
{
for(int i=0;i<n;i++)
{
System.out.print("汪~");
}
System.out.println();
}
Dog(String name,String color,int age,double weight)
{
this.name=name;
this.color=color;
this.age=age;
this.weight=weight;
}
}
複製代碼
作者:
高允懋
時間:
2018-10-20 15:04
package kao;
public class Main {
public static void main(String[] args) {
Dog dog = new Dog("憨憨",2,1.3,"紅棕色");
dog.showProfile();
dog.makeSound(3);
}
}
複製代碼
作者:
鄭楀諺
時間:
2018-10-20 15:04
package Morris;
public class Dog {
String name;
String color;
int age;
double weight;
public void showProfile()
{
System.out.println(String.format("%s今年%d歲,體重%f公斤,毛色為%s", this.name,this.age,this.weight,this.color));
}
public void makesound(int n)
{
for(int i=0;i<n;i++)
{
System.out.print("汪~");
}
System.out.println();
}
Dog(String name,String color,int age,double weight)
{
this.name=name;
this.color=color;
this.age=age;
this.weight=weight;
}
}
複製代碼
作者:
高允懋
時間:
2018-10-20 15:05
package kao;
public class Dog {
String name;
int age;
double weight;
String colar;
Dog(String name,int age,double weight,String colar){
this.name=name;
this.age=age;
this.weight=weight;
this.colar=colar;
}
public void showProfile(){
System.out.println(String.format("%s今年%d歲,體重%f公斤,毛色為%s",this.name,this.age,this.weight,this.colar));
}
public void makeSound(int n){
for(int i=0;i<n;i++)
System.out.print("汪~");
System.out.println();
}
}
複製代碼
作者:
彭煥宇
時間:
2018-10-20 15:05
package bbs.istak.org.tw;
public class Main {
public static void main(String[] args) {
// TODO 自動產生的方法 Stub
Dog dog = new Dog(2,1.3,"憨憨","紅棕色");
dog.showProfile();
dog.makeSound(2);
}
}
複製代碼
作者:
彭煥宇
時間:
2018-10-20 15:05
package bbs.istak.org.tw;
public class Dog {
int age;
double weight;
String name;
String color;
public void showProfile() {
System.out.println(
String.format("%s今年%d歲,體重%f公斤,毛色為%s",this.name,this.age,this.weight,this.color)
);
}
public void makeSound(int n){
for(int i=0;i<=n;i++)
System.out.print("汪~");
System.out.println();
}
Dog(int Age,double Weight,String Name,String Color){
this.age=Age;
this.weight=Weight;
this.name=Name;
this.color=Color;
}
}
複製代碼
作者:
湯東緯
時間:
2018-10-20 15:11
public class Main {
public static void main(String[] args) {
// TODO 自動產生的方法 Stub
Dog dog =new dog("憨憨",1,1.3,"紅棕色");
dog.ShowProfile();
dog.makesound(3);
public class Dog {
String name;
int age;
double weight;
String color;
public void ShowProfile()
{
System.out.println(String.format("%s今年%d歲,體重%f公斤毛色%s",this.name,this.age,this.weight,this.color));
}
public void makesound(int n)
{
for(int i=0;i<n;i++)
{
System.out.print("汪~");
}
System.out.println();
}
dog(String name,int age,double weight,String color)
{
this.name=name;
this.age=age;
this.weight=weight;
this.color=color;
}
}
}
}
複製代碼
作者:
高允懋
時間:
2018-10-20 15:33
package kao;
public class Main {
public static void main(String[] args) {
Dog dog = new Dog();
dog.name = "憨憨";
Dog dog1 = new Dog();
dog1.name = "球球";
System.out.println(dog.name);
System.out.println(dog.name);
}
}
複製代碼
package kao;
public class Dog {
static String name;
}
複製代碼
作者:
吳秉翰
時間:
2018-11-3 13:33
package bn.tw;
public class Dog {
String name;
int age;
double weight;
String color;
public Dog(String name, int age, double weight, String color) {
this.name = name;
this.age = age;
this.weight = weight;
this.color = color;
}
public void showProfile() {
System.out.println(String.format("%s今年%d歲,體重%f公斤,毛色是%s色"));
}
}
複製代碼
歡迎光臨 種子論壇 | 高雄市資訊培育協會學員討論區 (http://seed.istak.org.tw/)
Powered by Discuz! 7.2