Mid Term 1 Question Bank Oop..
Mid Term 1 Question Bank Oop..
24. Discuss the three ways to access package from outside the package? or CO3 2
Explain its types with suitable example.
25. Differentiate between Interface and Abstract Class in java. CO3 3
26. Explain how to extends an interface into another another interface with CO3 3
example?
27. Write a Java program to create a Animal interface with a method called bark() CO3 3
that takes no arguments and returns void. Create a Dog class that implements
Animal and overrides speak() to print "Dog is barking".
Ans: public interface Animal
{ void bark();
}
public class Dog implements Animal
{
@Override
public void bark()
{
System.out.println("Dog is barking!");
}
}
public class Main
{
public static void main(String[] args)
{
Dog dog = new Dog();
dog.bark();
}
}
28. What is the difference between an interface and class. With the help of suitable CO3 2
java program explain the purpose of interfaces in java.