让我们说我有班级狗:
public class Dog {
public String Breed { get; set; }
public String Color { get; set; }
...
}
Run Code Online (Sandbox Code Playgroud)
和一类动物:
public class Animals {
public Dog[] Dogs { get; set; }
public Dog[] GetDogs() {
...
return Dogs;
}
...
}
Run Code Online (Sandbox Code Playgroud)
上面的类在我的类库中,我添加它作为我的项目的参考..一切正常但我想要的是谁使用这个库不应该能够使用类Dog
,我的意思是他不应该做某事喜欢Dog dog = new Dog();
.我试图让它内部,但是,我必须在课堂上写内部Animals
,如果我这样做,我不能使用GetDogs()方法.
有什么建议?
我是Linux环境的新手,我刚开始使用gcc.我们有一个小项目,有7到8个cpp文件.当我尝试编译我的文件时,我想知道为什么每个.cpp文件都有.o文件.只有一个主要的.
如何在没有连接的情况下一个接一个地存储两个字符串(我们可以增加地址)
char str[10];
scanf("%s",str);
str=str+9;
scanf("%s",str);
Run Code Online (Sandbox Code Playgroud)
注意:如果我将第一个字符串作为BALA而第二个字符串作为HI,它应该在BALA之后打印为HI.但HI不应该取代BALA.
我正在使用地图,并希望使用值对象作为地图键...以及列表作为值.值对象有2个属性的第一个名称,第二个名称.如果两个属性都与同一个映射中的某个键匹配,则想要返回map.containsKey()为true.
我试着用比较器如下
public class comaparatorEx implements Comparator<Test>{
public static void main(String args[]){
Map m= new HashMap<Test,List<String>>();
Test t = new Test();
t.setFirstname("vamsi");
t.setSecondname("priya");
List descriptionList=new ArrayList();
descriptionList.add("description1");
m.put(t, descriptionList);
Test t2 = new Test();
t2.setFirstname("vamsi");
t2.setSecondname("priya");
if(m.containsKey(t2)){
System.out.println("user found");
}
}
public int compare(Test o1, Test o2) {
if((o1.firstname.equals(o2.firstname) )&& o1.secondname.equals(o2.secondname))
return 0;
else return 1;
}
}
Run Code Online (Sandbox Code Playgroud)
这是我正在使用的价值对象
public class Test {
String firstname;
String secondname;
public String getFirstname() {
return firstname;
}
public void setFirstname(String firstname) {
this.firstname …
Run Code Online (Sandbox Code Playgroud)