How to Access Default Attributes in Java


In this example we will show the method to access default attributes in Java.

Source Code

package com.beginner.examples;


class Student {
  String name = "Lucky";
  int age = 16;
  
  public static void main(String[] args) {
    Student s = new Student();
    System.out.println("Name: " + s.name); //access default attributes
    System.out.println("Age: " + s.age);
  }
}


Output:

Name: Lucky
Age: 16
Subscribe
Notify of
guest
0 Comments
Inline Feedbacks
View all comments