Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 945867
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T22:49:20+00:00 2026-05-15T22:49:20+00:00

Given the following code: public class A { static final long tooth = 1L;

  • 0

Given the following code:

public class A {
 static final long tooth = 1L;

 static long tooth(long tooth){
  System.out.println(++tooth);
  return ++tooth;
 }

 public static void main(String args[]){
  System.out.println(tooth);
  final long tooth = 2L;
  new A().tooth(tooth);
  System.out.println(tooth);
 }
}

Can you please explain me the concept of shadowing ?
And another thing, what tooth is actually used in the code from the main method ?

And i know it’s a very ugly code, but ugly is the standard choice for SCJP book writers.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-15T22:49:21+00:00Added an answer on May 15, 2026 at 10:49 pm

    There’s nothing magical about shadowing as a concept. It’s simply that a reference to a name will always be referencing the instance within the nearest enclosing scope. In your example:

    public class A {
     static final long tooth#1 = 1L;
    
     static long tooth#2(long tooth#3){
      System.out.println(++tooth#3);
      return ++tooth#3;
     }
    
     public static void main(String args[]){
      System.out.println(tooth#1);
      final long tooth#4 = 2L;
      new A().tooth#2(tooth#4);
      System.out.println(tooth#4);
    }
    

    }

    I’ve annotated each instance with a number, in the form “tooth#N”. Basically any introduction of a name that is already defined somewhere else will eclipse the earlier definition for the rest of that scope.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Given the following code: using System.Collections.Generic; static class Program { static void Main() {
Given the following code : import java.io.*; public class Main { public static void
Given the following code... class Program { static void Main(string[] args) { Foo foo
Given the following code sample: public class WeirdStuff { public static int doSomething() {
Given the following code: public class FooBar { public static volatile ConcurrentHashMap myConfigData =
Confusing question, I know. Given the following: class Test { public static void GenericFunc<T>(T
Given the following: class BC { public void Display() { System.Console.WriteLine(BC::Display); } } class
I currently have the following code: public class Count { public static void countChar()
given the following code: public static class Helpers { private static Char[] myChars =
Given the following Java code: public class Test { static private class MyThread extends

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.