Correct Answer: A protected method may only be accessed by classes or interfaces of the same package or by subclasses of the class in which it is declared
2. What do you understand by private, protected and public?
Correct Answer: These are accessibility modifiers Private is the most restrictive, while public is the least restrictive There is no real difference between protected and the default type (also known as package protected) within the context of the same package, however the protected keyword allows visibility to a derived class in a different package
Correct Answer: A thread is a lightweight subprocess, a smallest unit of processing It is a separate path of execution It shares the memory area of process As shown in the above figure, thread is executed inside the process There is context-switching between the threads There can be multiple processes inside the OS and one process can have multiple threads
4. What is the difference between creating a thread by extending Thread class and by implementing Runnable interface? Which one should prefer?
Correct Answer: When creating a thread by extending the Thread class, it is not mandatory to override the run method (If we are not overriding the run method , it is useless), because Thread class have already given a default implementation for run method But if we are implementing Runnable , it is mandatory to override the run method The preferred way to create a thread is by implementing Runnable interface, because it give loose coupling
5. What are the the different ways for creating a thread?
Correct Answer: The classloader is a subsystem of JVM that is used to load classes and interfacesThere are many types of classloaders eg Bootstrap classloader, Extension classloader, System classloader, Plugin classloader etc
7. What will be the output of the following code snippet? Object s1 = new String("Hello"); Object s2 = new String("Hello"); if(s1 == s2) { System.out.println("s1 and s2 are =="); }else if (s1.equals(s2)) { System.out.println("s1 and s2 are equals()"); }
Correct Answer: JDBC technology is an API (included in both J2SE and J2EE releases) that provides cross-DBMS connectivity to a wide range of SQL databases and access to other tabular data sources, such as spreadsheets or flat files With a JDBC technology-enabled driver, you can connect all corporate data even in a heterogeneous environment
Correct Answer: A table of data representing a database result set, which is usually generated by executing a statement that queries the database ResultSet object maintains a cursor pointing to its current row of data Initially the cursor is positioned before the first row The next method moves the cursor to the next row, and because it returns false when there are no more rows in the ResultSet object, it can be used in a while loop to iterate through the result set