Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Create 57_javaBeginners.java #147

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
43 changes: 43 additions & 0 deletions Java_Beginners/59_javaBeginners.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
// apples.java file

class Apples{
public static void main(String[] args){

DogList DLO = new DogList();
Dog d = new Dog();
DLO.add(d);
}
}

//Dog.java file

public class Dog extends Animal{

}

//Fish.java file

public class Fish extends Animal{

}

//Animal.java file

public class Animal{

}

//DogList.java file

public class DogList{
private Dog[] thelist = new Dog[5];
private int i=0;

public void add(Dog d){
if(i<thelist.length){
thelist[i]=d;
System.out.println("Dog added at index "+i);
i++;
}
}
}
46 changes: 46 additions & 0 deletions Java_Beginners/60_javaBeginners.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
// apples.java file

class Apples{
public static void main(String[] args){

AnimalList ALO = new AnimalList();
Dog d = new Dog();
Fish f = new Fish();
ALO.add(d);
ALO.add(f);
}
}

//Dog.java file

public class Dog extends Animal{

}

//Fish.java file

public class Fish extends Animal{

}

//Animal.java file

public class Animal{

}

//AnimalList.java file

public class AnimalList{

private Animal[] thelist = new Animal[5];
private int i = 0;

public void add(Animal a){
if(i<thelist.length){
thelist[i]=a;
System.out.println("Animal added at index "+a);
i++;
}
}
}