Statistics
39
Views
0
Downloads
0
Donations
Support
Share
Uploader

高宏飞

Shared on 2026-01-15

AuthorJavin Paul

This book contains frequently asked questions and their answer/explanations on essential Java topics. You can use this book to revise all essential Java concepts before your interview quickly, and you can also use this book to learn Core Java in depth. Crack your Java interview by preparing important topics and mastering key concepts in a guided and structured way in a short time. Cracking a Java Interview is not easy, and one of the main reasons for that is Java is very vast. There are a lot of concepts and APIs to master to become a decent Java developer. Many people who are good at general topics like Data Structure and Algorithms, System Design, SQL, and Databases fail to crack the Java interview because they don't spend time learning the Core Java concepts and essential APIs and packages like Java Collection Framework, Multithreading, JVM Internals, JDBC, Design Patterns, and Object-Oriented Programming. This book aims to fill that gap and introduce you to classical Java interview questions on these topics. By going through these questions and topics, you will not only expand your knowledge but also get ready for your Next Java interview. This book is for programmers preparing for Java interviews. This book contains frequently asked questions and their answer/explanations on essential Java topics. You can use this book to quickly revise all essential Java concepts before your interview, both telephonic and face-to-face, and you can also use this book to learn Core Java in depth. This book contains frequently asked Java questions from essential topics like 1. Object-Oriented Programming 2. Java Fundamentals 3. Java Collections 4. Java Multithreading 5. Garbage Collection 6. JDBC 7. Generics 8. Design Patterns 9. Telephonic Interview Questions These questions are a compilation of my best Java interview articles which millions of Java developers have read, and it is also my ten years of experience writing Java articles, tutorials, and interview ques

Tags
No tags
Publish Year: 2022
Language: 英文
Pages: 159
File Format: PDF
File Size: 3.2 MB
Support Statistics
¥.00 · 0times
Text Preview (First 20 pages)
Registered users can read the full content for free

Register as a Gaohf Library member to read the complete e-book online for free and enjoy a better reading experience.

(This page has no text content)
Table Of Contents PREFACE 1 OBJECT ORIENTED PROGRAMMING INTERVIEW QUESTIONS 2 What is method overloading in OOP or Java? 3 What is the method overriding in OOP or Java? 4 Is Java a pure object-oriented language? if not why? 4 The difference between method overloading and overriding? 5 Can we overload a static method in Java? 6 Can we override the static method in Java? 6 Can we prevent overriding a method without using the final modifier? 6 Can we override a private method in Java? 6 What is the covariant method overriding in Java? 7 Can we change the return type of method to subclass while overriding? 7 Can we change the argument list of an overriding method? 7 Can we override a method that throws runtime exception without throws clause? 8 How do you call a superclass version of an overriding method in a subclass? 8 Can we override a non-static method as static in Java? 8 Can we override the final method in Java? 8 Can we have a non-abstract method inside an interface? 9 What is the default method of Java 8? 9 What is an abstract class in Java? 10 What is an interface in Java? What is the real user of an interface? 10 The difference between Abstract class and interface? 10 Can we make a class abstract without an abstract method? 11 Can we make a class both final and abstract at the same time? 11 Can we overload or override the main method in Java? 11 What is the difference between Polymorphism, Overloading, and Overriding? 12 Can an interface extend more than one interface in Java? 12 Can a class extend more than one class in Java? 12 What is the difference between abstraction and polymorphism in Java? 12 OBJECT-ORIENTED DESIGN PRINCIPLE AND PATTERN INTERVIEW QUESTIONS 13 What problem is solved by the Strategy pattern in Java? 13 Which OOP concept Decorator design Pattern is based upon? 14 When to use the Singleton design pattern in Java? 14 What is the difference between State and Strategy Patterns? 15 What is the difference between Association, Aggregation, and Composition in OOP? 15
What is the difference between Decorator, Proxy and Adapter pattern in Java? 15 What is the 5 objects oriented design principle from SOLID? 16 What is the difference between Composition and Inheritance in OOP? 17 INTERVIEW QUESTIONS FROM TELEPHONIC ROUND 18 1) Difference between String, StringBuffer and StringBuilder in Java? 19 2) Difference between extends Thread vs implements Runnable in Java? 19 3) Difference between Runnable and Callable interface in Java? 20 4) Difference between ArrayList and LinkedList in Java? 20 5) What is difference between wait and notify in Java? 20 6) Difference between HashMap and Hashtable in Java? 21 7) Difference between TreeSet and TreeMap in Java? 21 8) Write a Java program to print Fibonacci series? 21 9) Write a Java program to check if a number is Prime or not? 22 10) How to Swap two numbers without using temp variable? 22 11) How to check if linked list contains loop in Java? 22 12) Write Java program to reverse String without using API? 23 13) Difference between Serializable and Externalizable in Java? 23 14) Difference between transient and volatile in Java? 23 15) Difference between abstract class and interface? 24 16) Difference between Association, Composition and Aggregation? 24 17) What is difference between FileInputStream and FileReader in Java? 25 18) How do you convert bytes to character in Java? 25 19) Can we have return statement in finally clause? What will happen? 25 20) Can you override static method in Java? 26 21) Difference between private, public, package and protected in Java? 26 22) 5 Coding best practices you learned in Java? 26 23) Write a Program to find maximum and minimum number in array? 27 24) Write a program to reverse Array in place? 27 25) Write a program to reverse a number in Java? 28 26) Write a Program to calculate factorial in Java? 28 27) What is difference between calling start() and run() method of Thread? 28 28) Write a Program to solve Producer Consumer problem in Java? 29 29) How to find middle element of linked list in one pass? 29 30) What is equlas() and hashCode() contract in Java? Where does it used? 30 31) Why wait and notify methods are declared in Object class? 30 32) How does HashSet works in Java? 31 33) What is difference between synchronize and concurrent Collection in Java? 31 34) What is difference between Iterator and Enumeration in Java? 31 35) What is difference between Overloading and Overriding in Java? 32 36) Difference between static and dynamic binding in Java? 32
37) Difference between Comparator and Comparable in Java? 33 38) How do you sort ArrayList in descending order? 33 39) What is the difference between PATH and CLASSPATH in Java? 34 40) What is the difference between Checked and Unchecked Exception in Java? 34 MULTITHREADING AND CONCURRENCY INTERVIEW QUESTIONS 36 1) What is Thread in Java? 38 2) What is the difference between Thread and Process in Java? 39 3) How do you implement Thread in Java? 39 4) When to use Runnable vs Thread in Java? 39 6) What is the difference between start() and run() method of Thread class? 40 7) What is the difference between Runnable and Callable in Java? 40 8) What is the difference between CyclicBarrier and CountDownLatch in Java? 41 9) What is Java Memory model? 41 10) What is volatile variable in Java? 42 11) What is thread-safety? is Vector a thread-safe class? 43 12) What is race condition in Java? Given one example? 43 13) How to stop a thread in Java? 44 14) What happens when an Exception occurs in a thread? 44 15) How do you share data between two thread in Java? 45 16) What is the difference between notify and notifyAll in Java? 45 17) Why wait, notify and notifyAll are not inside thread class? 46 18) What is ThreadLocal variable in Java? 46 19) What is FutureTask in Java? 47 20) What is the difference between the interrupted() and isInterrupted() method in Java? 48 21) Why wait and notify method are called from synchronized block? 48 22) Why should you check condition for waiting in a loop? 49 23) What is the difference between synchronized and concurrent collection in Java? 49 24) What is the difference between Stack and Heap in Java? 50 25) What is thread pool? Why should you thread pool in Java? 51 26) Write code to solve Producer Consumer problem in Java? 51 27) How do you avoid deadlock in Java? Write Code? 52 28) What is the difference between livelock and deadlock in Java? 53 29) How do you check if a Thread holds a lock or not? 54 30) How do you take thread dump in Java? 54 31) Which JVM parameter is used to control stack size of a thread? 54 32) What is the difference between synchronized and ReentrantLock in Java? 55 33) There are three threads T1, T2, and T3? How do you ensure sequence T1, T2, T3 in Java? 55
34) What does yield method of Thread class do? 55 35) What is the concurrency level of ConcurrentHashMap in Java? 56 36) What is Semaphore in Java? 56 37) What happens if you submit a task when the queue of the thread pool is already filled? 57 38) What is the difference between the submit() and execute() method thread pool in Java? 57 39) What is blocking method in Java? 57 40) Is Swing thread-safe? What do you mean by Swing thread-safe? 58 41) What is the difference between invokeAndWait and invokeLater in Java? 58 42) Which method of Swing API are thread-safe in Java? 59 43) How to create an Immutable object in Java? 59 44) What is ReadWriteLock in Java? 60 45) What is busy spin in multi-threading? 60 46) What is the difference between the volatile and atomic variable in Java? 61 47) What happens if a thread throws an Exception inside synchronized block? 61 48) What is double checked locking of Singleton? 62 49) How to create thread-safe Singleton in Java? 62 50) List down 3 multi-threading best practice you follow? 63 51) How do you force to start a Thread in Java? 64 52) What is the fork-join framework in Java? 65 53) What is the difference between calling wait() and sleep() method in Java multi-threading? 65 COLLECTION FRAMEWORK INTERVIEW QUESTIONS 67 1. How does HashMap work in Java? 68 2. What is the difference between poll() and remove() method of Queue interface? 69 3. What is the difference between fail-fast and fail-safe Iterators? 69 4. How do you remove an entry from a Collection? and subsequently what is the difference between the remove() method of Collection and remove() method of Iterator, which one you will use while removing elements during iteration? 70 5. What is the difference between Synchronized Collection and Concurrent Collection? 70 6. What is the difference between Iterator and Enumeration? 71 7. How does HashSet is implemented in Java, How does it use Hashing? 71 8. What do you need to do to use a custom object as a key in Collection classes like Map or Set? 72 9. The difference between HashMap and Hashtable? 73 10. When do you use ConcurrentHashMap in Java? 73 11. What is the difference between Set and List in Java? 73 12. How do you Sort objects on the collection? 74
13. What is the difference between Vector and ArrayList? 74 14. What is the difference between HashMap and HashSet? 75 15) What is NavigableMap in Java? What is a benefit over Map? 75 16) Which one you will prefer between Array and ArrayList for Storing object and why? 76 17) Can we replace Hashtable with ConcurrentHashMap? 76 18) What is CopyOnWriteArrayList, how it is different than ArrayList and Vector? 77 19) Why ListIterator has added() method but Iterator doesn’t or Why to add() method is declared in ListIterator and not on Iterator. 78 20) When does ConcurrentModificationException occur on iteration? 78 21) Difference between Set, List and Map Collection classes? 79 22) What is BlockingQueue, how it is different than other collection classes? 80 23) How does LinkedList is implemented in Java, is it a Singly or Doubly linked list? 80 24) How do you iterator over Synchronized HashMap, do you need to lock iteration and why? 80 25) What is Deque? when do you use it? 80 SERIALIZATION INTERVIEW QUESTIONS 81 1. What is a Serializable interface? What is the purpose of it? 83 2. What is the difference between the Serializable and Externalizable interface? 83 3. What is a transient variable? What is the purpose of it? 83 4. What is SerialVersionUID in Java? Why it’s important? 84 5. How many methods we have in the Serializable interface? 85 6. What is a marker interface in Java? 85 7. Can you add a field in a Serializable class which doesn’t implement Serializable interface? 85 8. How do you serialize an object in Java? 86 9. How Serialization of an object works in Java? 86 10. What about static variables? Are they Serialized? 87 11. What is the difference between the transient and volatile variables in Java? 87 12. Can you make a subclass NotSerializable if the Superclass is Serializable? Is it mandatory for a subclass to implement the Serializable interface? 87 13. Do you know any alternative to Serialization for Java application? 88 DESIGN PATTERN INTERVIEW QUESTIONS 90 1. What is the Decorator pattern in Java? Can you give an example of a Decorator pattern? 92 2. When to use the Strategy Design Pattern in Java? 93
3. What is the Observer design pattern in Java? When do you use the Observer pattern in Java? 95 4. What is the difference between Strategy and State design Pattern in Java? 95 5. When to use the Composite design pattern in Java? Have you used it previously in your project? 95 6. What is the Singleton pattern in Java? 96 7. Can you write thread-safe Singleton in Java? 97 8. When to use the Template method design pattern in Java? 97 9. What is the Factory pattern in Java? What is the advantage of using a static factory method to create an object? 97 10. What is the difference between Decorator and Proxy pattern in Java? 98 11. When to use Setter and Constructor Injection in the Dependency Injection pattern? 99 12. What is the difference between Factory and Abstract Factory in Java 99 13. When to use the Adapter pattern in Java? Have you used it before in your project? 99 14. Can you write code to implement a producer-consumer design pattern in Java? 100 15. What is the Builder design pattern in Java? When do you use the Builder pattern? 100 16. What is the Open closed design principle in Java? 101 17. Can you give an example of SOLID design principles in Java? 101 18. What is the difference between Abstraction and Encapsulation in Java? 102 GARBAGE COLLECTION INTERVIEW QUESTIONS 103 Question 1 - What is the structure of Java Heap? What is Perm Gen space in Heap? 105 Question 2 - How do you identify minor and major garbage collection in Java? 105 Question 3 - What is the difference between ParNew and DefNew Young Generation Garbage collector? 106 Question 4 - How do you find GC resulted due to calling System.gc()? 106 Question 5 - What is the difference between Serial and Throughput Garbage collectors? 107 Question 6 – When does an Object becomes eligible for Garbage collection in Java? 108 Question 7 - What is finalize method in Java ? When does Garbage collector calls finalize method in Java? 108 Question 8 - If Object A has reference to Object B and Object B refer to Object A, apart from that there is no live reference to either object A or B, Does they are eligible to Garbage collection? 109 Question 9 -Can we force the Garbage collector to run at any time? 109
Question 10 - Does Garbage collection occur in permanent generation space in JVM? 109 Question 11 : How to you monitor garbage collection activities? 110 Question 12: Look at below Garbage collection output and answer following question : 111 GENERICS INTERVIEWS QUESTIONS 114 1. What is Generics in Java ? What are advantages of using Generics? 115 2. How Generics works in Java ? What is type erasure ? 116 3. What is Bounded and Unbounded wildcards in Generics ? 116 5. How to write a generic method which accepts generic argument and return Generic Type? 117 6. How to write parametrized class in Java using Generics ? 118 7. Write a program to implement LRU cache using Generics ? 118 8. Can you pass List<String> to a method which accepts List<Object> 118 9. Can we use Generics with Array? 119 10. How can you suppress unchecked warning in Java ? 119 Difference between List<Object> and raw type List in Java? 120 Difference between List<?> and List<Object> in Java? 120 Difference between List<String> and raw type List. 121 JDBC INTERVIEW QUESTIONS 123 Question 1: What is JDBC? 124 Question 2: What are the main steps in java to make JDBC connectivity? 124 Question 3: What is the mean of “dirty read“ in database? 125 Question 4: What is the 2 phase commit? 126 Question 5: What are different types of Statement? 127 Question 6: How cursor works in scrollable result set? 128 Question 7: What is connection pooling? 129 Question 8: What do you mean by cold backup, hot backup? 129 Question 9: What are the locking system in JDBC 130 Question 10: Does the JDBC-ODBC Bridge support multiple concurrent open statements per connection? 130 STREAM AND FUNCTIONAL PROGRAMMING INTERVIEW QUESTIONS 131 1. What is the difference between Collection and Stream? 132 2. What does the map() function do? why you use it? 133 3. What does the filter() method do? when you use it? 134 4. What does the flatmap() function do? why you need it? 134 5. What is difference between flatMap() and map() functions? 135 6. What is the difference between intermediate and terminal operations on Stream? 136
7. What does the peek() method do? When should you use it? 137 8. What do you mean by saying Stream is lazy? 137 9. What is a functional interface in Java 8? 138 10. What is the difference between a normal and functional interface in Java? 138 11. What is the difference between the findFirst() and findAny() method? 139 12. What is a Predicate interface? 139 13. What are Supplier and Consumer Functional interface? 140 14. Can you convert an array to Stream? How? 141 15. What is the parallel Stream? How can you get a parallel stream from a List? 141 APPENDIX 143 My favorite tip to Crack Java Interview 143 INDEX 145
1GROKKING THE JAVA INTERVIEW PREFACE Cracking a Java Interview is not easy and one of the main reason for that is Java is very vast. There are lot of concepts and APIs to master to become a decent Java developer. Many people who are good at general topics like Data Structure and Algorithms, System Design, SQL and Database fail to crack the Java interview because the don’t spend time to learn the Core Java concepts and essential APIs and packages like Java Collection Framework, Multithreading, JVM Internals, JDBC, Design Patterns and Object Oriented Programming. This book aims to fill that gap and introduce you will classical Java interview questions from these topics. By going through these questions and topic you will not only expand your knowledge but also get ready for your Next Java interview. If you are preparing for Java interviews then I highly recommend you go through these questions before your telephonic or face-to- face interviews, you will not only gain confidence and knowledge to answer the question but also learn how to drive Java interview in your favor. This is the single most important tip I can give you as a Java developer. Always, remember, your answers drive interviews, and these questions will show you how to drive Interviewer to your strong areas. All the best for Java interview and if you have any questions or feedback you can always contact me on twitter javinpaul or comment on my blogs Javarevisited and Java67.
2GROKKING THE JAVA INTERVIEW OBJECT ORIENTED PROGRAMMING INTERVIEW QUESTIONS Java is an object-oriented programming language and you will see a lot of object-oriented programming concept questions on Java interviews. The classic questions like the difference between an interface and abstract class are always there but from the last couple of years more sophisticated questions based upon advanced design principles and patterns are also asked to check OOP knowledge of the candidate. Though, Object-oriented programming questions are more popular on Java interviews for 1 to 3 years experienced programmers. It makes sense as well, as these are the programmers who must know the OOP basics like Abstraction, Inheritance, Composition, Class, Object, Interface, Encapsulation, etc. If you look for Java interview questions for 2 to 4 years experienced programmer, you will find lots of questions based upon OOP fundamentals like Inheritance and Encapsulation but as you gain more experience, you will see questions based on object- oriented analysis and design e.g. code a vending design machine or implement a coffeemaker in Java.
3GROKKING THE JAVA INTERVIEW These questions are more difficult and require not only a true understanding of OOP fundamentals but also about SOLID design principles and patterns. In this section, I am going to share with you some OOPS concept based Java interview questions that I have collected from friends and colleagues and they have seen in various Java interviews on different companies. They are mostly asked at first a few rounds like on screening round or on the telephonic round. If you are a senior Java developer then you already know answers to this question and I suggest you practice more on object-oriented analysis and design skill i.e. how to do code against a specification. If you are fresher and junior Java developer with 2 to 3 years experience then you must revise these questions, learn if you don’t know to do well on your Java Job interviews. What is method overloading in OOP or Java? It’s one of the oldest OOPS concept questions, I have seen it 10 years ago and still sees it now. When we have multiple methods with the same name but different functionality then it’s called method overloading. For example. System.out.println() is overloaded as we have a 6 or 7 println() method each accepting a different type of parameter.
4GROKKING THE JAVA INTERVIEW What is the method overriding in OOP or Java? It’s one of the magic of object-oriented programming where the method is chose based upon an object at runtime. In order for method overriding, we need Inheritance and Polymorphism, as we need a method with the same signature in both superclass and subclass. A call to such a method is resolved at runtime depending upon the actual object and not the type o variable. What is the method of hiding in Java? When you declare two static methods with same name and signature in both superclass and subclass then they hide each other i.e. a call to the method in the subclass will call the static method declared in that class and a call to the same method is superclass is resolved to the static method declared in the super- class. Is Java a pure object-oriented language? if not why? Java is not a pure object-oriented programming language e.g. there are many things you can do without objects e.g. static methods. Also, primitive variables are not objects in Java.
5GROKKING THE JAVA INTERVIEW What are the rules of method overloading and overriding in Java? One of the most important rules of method overloading in Java is that the method signature should be different i.e. either the number of arguments or the type of arguments. Simply changing the return type of two methods will not result in overloading, instead, the compiler will throw an error. On the other hand, method overriding has more rules e.g. name and return type must be the same, method signature should also be the same, the overloaded method cannot throw a higher exception, etc. The difference between method overloading and overriding? Several differences but the most important one is that method overloading is resolved at compile- time and method overriding is resolved at runtime. The compiler only used the class information for method overloading, but it needs to know the object to resolved overridden method calls. This diagram explains the difference quite well, though:
6GROKKING THE JAVA INTERVIEW Can we overload a static method in Java? Yes, you can overload a static method in Java. You can declare as many static methods of the same name as you wish provided all of them have different method signatures. Can we override the static method in Java? No, you cannot override a static method because it’s not bounded to an object. Instead, static methods belong to a class and resolved at compile time using the type of reference variable. But, Yes, you can declare the same static method in a subclass, that will result in method hiding i.e. if you use the reference variable of type subclass then new method will be called, but if you use the reference variable of superclass than old method will be called. Can we prevent overriding a method without using the final modifier? Yes, you can prevent the method overriding in Java without using the final modifier. In fact, there are several ways to accomplish it e.g. you can mark the method private or static, those cannot be overridden. Can we override a private method in Java? No, you cannot. Since the private method is only accessible and visible inside the class they are declared, it’s not possible to override them in
7GROKKING THE JAVA INTERVIEW subclasses. Though, you can override them inside the inner class as they are accessible there. What is the covariant method overriding in Java? In the covariant method overriding, the overriding method can return the subclass of the object returned by the original or overridden method. This concept was introduced in Java 1.5 (Tiger) version and it’s very helpful in case the original method is returning general type like Object class, because, then by using the covariant method overriding you can return a more suitable object and prevent client-side typecasting. One of the practical use of this concept is when you override the clone() method in Java. Can we change the return type of method to subclass while overriding? Yes, you can, but only from Java 5 onward. This feature is known as covariant method overriding and it was introduced in JDK 5 release. This is immensely helpful if the original method return super-class like clone() method return java.lang.Object. By using this, you can directly return the actual type, preventing client-side type-casting of the result. Can we change the argument list of an overriding method? No, you cannot. The argument list is part of the method signature and both overriding and overridden
8GROKKING THE JAVA INTERVIEW methods must have the same signature. Can we override a method that throws runtime exception without throws clause? Yes, there is no restriction on unchecked exceptions while overriding. On the other hand, in the case of checked exception, an overriding exception cannot throw a checked exception which comes higher in type hierarchy e.g. if the original method is throwing IOException than the overriding method cannot throw java.lang.Exception or java.lang.Throwable. How do you call a superclass version of an overriding method in a subclass? You can call a superclass version of an overriding method in the subclass by using super keyword. For example to call the toString() method from java. lang.Object class, you can call super.toString(). Can we override a non-static method as static in Java? Yes, you can override the non-static method in Java, no problem on them but it should not be private or final :) Can we override the final method in Java? No, you cannot override a final method in Java, the final keyword with the method is to prevent method
9GROKKING THE JAVA INTERVIEW overriding. You use the final when you don’t want subclass changing the logic of your method by overriding it due to security reasons. This is why the String class is final in Java. This concept is also used in the template design patterns where the template method is made final to prevent overriding. Can we have a non-abstract method inside an interface? From Java 8 onward you can have a non-abstract method inside interface, prior to that it was not allowed as all method was implicitly public abstract. From JDK 8, you can add static and default methods inside an interface. What is the default method of Java 8? The default method, also known as the extension method is new types of the method which you can add on the interface now. These method has implementation and intended to be used by default. By using this method, JDK 8 managed to provide common functionality related to lambda expression and stream API without breaking all the clients which implement their interfaces. If you look at Java 8 API documentation you will find several useful default methods on key Java interface like Iterator, Map, etc.
10GROKKING THE JAVA INTERVIEW What is an abstract class in Java? An abstract class is a class that is incomplete. You cannot create an instance of an abstract class in Java. They are provided to define default behavior and ensured that client of that class should adore to those contract which is defined inside the abstract class. In order to use it, you must extend and implement their abstract methods. BTW, in Java, a class can be abstract without specifying any abstract method. What is an interface in Java? What is the real user of an interface? Like an abstract class, the interface is also there to specify the contract of an API. It supports the OOP abstraction concept as it defines only abstract behavior. It will tell that your program will give output but how is left to implementors. The real use of the interface to define types to leverage Polymorphism. The difference between Abstract class and interface? In Java, the key difference is that abstract class can contain a non-abstract method but the interface cannot, but from Java 8 onward interface can also contain static and default methods that are non- abstract.
11GROKKING THE JAVA INTERVIEW Can we make a class abstract without an abstract method? Yes, just add abstract keyword on the class definition and your class will become abstract. Can we make a class both final and abstract at the same time? No, you cannot apply both final and abstract keyword at the class at the same time because they are exactly opposite of each other. A final class in Java cannot be extended and you cannot use an abstract class without extending and make it a concrete class. As per Java specification, the compiler will throw an error if you try to make a class abstract and final at the same time. Can we overload or override the main method in Java? No, since main() is a static method, you can only overload it, you cannot override it because the static