慕粉0713393144
2017-09-08 17:19
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace protest
{
class Program
{
static void Main(string[] args)
{
dog dog1 = new dog();
dog1.name = "jack";
dog1.printname();
}
}
}
public class pet
{
public string name;
public void printname() { Console.WriteLine("宠物的名字是"+"name"); }
}
public class dog : pet { }
using System;
using System.Collections.Generic;
using System.Text;
namespace Test
{
public class Pet
{
public string Name;
public void PrintName()
{
Console.WriteLine("Pet's name is" + Name);
}
public int Age;
public void PrintAge()
{
Console.WriteLine("Pet's age is " + Age);
}
}
public class dog:Pet
{
}
public class cat:Pet
{
}
class Program
{
static void Main(string[] args)
{
dog dog = new dog();
dog.Name = "jack";
dog.Age = 18;
dog.PrintName();
dog.PrintAge();
cat cat = new cat();
cat.Name = "tom";
cat.Age = 3;
cat.PrintName();
cat.PrintAge();
}
}
}
namespace ConsoleApplication1
{
class Program
{
public class pet : Program
{
public string cat;
public void name()
{
Console.Write("pet's name is " + cat);
}
}
public class coffecat : pet
{
}
static void Main(string[] args)
{
coffecat cats = new coffecat();
cats.cat = "coffecat";
cats.name();
Console.ReadLine();
}
}
}
第一,你把 类 放到 namespace 外面去了,不行哦~
第二,再console。writeline 里面 如果是一个值,不能加“”。
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace protest
{
class Program
{
static void Main(string[] args)
{
dog dog1 = new dog();
dog1.name = "jack";
dog1.printname();
}
}
public class pet
{
public string name;
public void printname() { Console.WriteLine("宠物的名字是"+ name); }
}
public class dog : pet
{
}
}
C#面向对象编程
68857 学习 · 153 问题
相似问题