Four Pillars of OOPs
Problem
Question: What are the four pillars of OOPs? Explain them.
Answer: The four pillars of Object-Oriented Programming are:
Technical
1 sections, 5 questions
Question: What are the four pillars of OOPs? Explain them.
Answer: The four pillars of Object-Oriented Programming are:
Question: What are the differences between Abstraction and Encapsulation?
Answer:
Question: Is there any way to achieve compile-time polymorphism?
Answer: Yes, compile-time (static) polymorphism can be achieved in two ways:
Question: Write a program to print something without using the main function.
Solution (C++): In C++, this can be done using a static initializer that runs before main():
In C++, this can be done using a static initializer that runs before main():
#include <iostream>
using namespace std;
class Init {
public:
Init() {
cout << "Printed without main function!" << endl;
}
};
Init obj;
int main() {
return 0;
}Question: Write a program to check whether a string is a valid anagram of another.
Solution (Java):
import java.util.Arrays;
public class ValidAnagram {
public static boolean isAnagram(String s1, String s2) {
if (s1.length() != s2.length()) return false;
char[] a1 = s1.toCharArray();
char[] a2 = s2.toCharArray();
Arrays.sort(a1);
Arrays.sort(a2);
return Arrays.equals(a1, a2);
}
public static void main(String[] args) {
System.out.println(isAnagram("listen", "silent"));
}
}