en
Feedback
Java Questions Repository

Java Questions Repository

Open in Telegram

Here is Java Interview Questions Repository. Our goal is to help you prepare as thoroughly as possible for your next big opportunity. and Our id is @DukeProject that is the Java mascot, which was open sourced by Sun Microsystems on November 13, 2006.

Show more
Buy Ad
467
Subscribers
No data24 hours
-17 days
No data30 days
Posts Archive
Which statements about polymorphism and method inheritance are correct? (Choose all that apply.)
Anonymous voting

Which statements about polymorphism and method inheritance are correct? (Choose all that apply.)
 
A. Given an arbitrary instance of a class, it cannot be determined until runtime which overridden method will be executed in a parent class. 
-
 
B. It cannot be determined until runtime which hidden method will be executed in a parent class. 
-
 
C. Marking a method static prevents it from being overridden or hidden. 
-
 
D. Marking a method final prevents it from being overridden or hidden. 
-
 
E. The reference type of the variable determines which overridden method will be called at runtime. 
-
 
F. The reference type of the variable determines which hidden method will be called at runtime.

sticker.webp0.32 KB

What is printed by the following program?
Anonymous voting

In this code:
public class Deer { 
    enum Food {APPLES, BERRIES, GRASS} 
     protected class Diet { 
          private Food getFavorite() { 
                return Food.BERRIES; 
          } 
 } 
 public static void main(String[] seasons) { 
     System.out.print(switch(new Diet().getFavorite()) { 
     case APPLES -> "a"; 
     case BERRIES -> "b"; 
     default -> "c"; 
      }); 
 } }

sticker.webp0.32 KB

Which lines of the following interface declarations do not compile? (Choose all that apply.)
Anonymous voting

In this code:
1: public interface Omnivore { 
2:    int amount = 10; 
3:    static boolean gather = true; 
4:    static void eatGrass() {} 
5:    int findMore() { return 2; } 
6:    default float rest() { return 2; } 
7:    protected int chew() { return 13; } 
8:    private static void eatLeaves() {} 
9: }

sticker.webp0.32 KB

Which of the following are true about encapsulation? (Choose all that apply.)
Anonymous voting

sticker.webp0.32 KB

The following code appears in a file named Ostrich.java. What is the result of compiling the source file?
Anonymous voting

In this code:
1: public class Ostrich { 
2:     private int count; 
3:     static class OstrichWrangler { 
4:           public int stampede() { 
5:                    return count; 
6:            } } }

sticker.webp0.32 KB

Which lines, when entered independently into the blank, allow the code to print Not scared at runtime? (Choose all that apply.)
Anonymous voting

In this code:
public class Ghost { 
    public static void boo() { 
        System.out.println("Not scared"); 
    } 
    protected final class Spirit { 
        public void boo() { 
               System.out.println("Booo!!!"); 
        } 
    }
    public static void main(String... haunt) { 
               var g = new Ghost().new Spirit() {}; 
               ------------------------------------------------------; 
    } 
}

sticker.webp0.32 KB

What is the result of the following program?
Anonymous voting

in this code:
public class Weather { 
    enum Seasons { 
        WINTER, SPRING, SUMMER, FALL 
    }
public static void main(String[] args) { 
     Seasons v = null; 
     switch (v) { 
          case Seasons.SPRING -> System.out.print("s"); 
          case Seasons.WINTER -> System.out.print("w"); 
          case Seasons.SUMMER -> System.out.print("m"); 
          default -> System.out.println("missing data"); } 
      } 
}

sticker.webp0.32 KB