Skip to content
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
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
public class Sample{
public static void main(String[] args) {
Dog dog = new Dog();
dog.foo();
dog.bar();

}
}
Expand All @@ -14,4 +17,4 @@ class Dog extends Animal{
void bar(){
System.out.println("I am a Dog");
}
}
}
Original file line number Diff line number Diff line change
@@ -1,3 +1,30 @@

class Test {

/**
* @param args the command line arguments
*/
public static void main(String[] args) {



Dog dog = new Dog();

dog.setBreed("German Sheperd");
dog.setAge(5);
dog.setColor("Brown");
dog.setSize(2);


System.out.println(dog.getBreed());
System.out.println(dog.getAge()+" years old ");
System.out.println(dog.getColor()+" color");
System.out.println(dog.getSize() +" feet height");
}

}


public class Dog {

//using private access modifiers
Expand Down Expand Up @@ -32,6 +59,8 @@ public int getAge() { //getter to get age
public void setAge(int age) { //setter to set age
Age = age;
}



public int getSize() { //getter to get size
return Size;
Expand All @@ -40,3 +69,4 @@ public int getSize() { //getter to get size
public void setSize(int size) { //setter to set size
Size = size;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,19 @@ public class sample {
public static void main(String[] args) {
Dog dog=new Dog();//create a dog object
dog.animalSound();

dog.animalFeature();

}
}
//abstract class
abstract class Animal{
// Abstract method (does not have a body)
public abstract void animalSound();

public void animalFeature(){
System.out.println("Has 4 legs/limbs");

}
}

// Subclass (inherit from Animal)
Expand Down