// Student is the classclassStudent{Stringname="Momo";}// Main class to test the Student classpublicclassMain{publicstaticvoidmain(String[]args){// s1 is the object of the Student classStudents1=newStudent();System.out.println(s1.name);}}
constructor in java
java code:
// Student classclassStudent{Stringname;// Instance variable// ConstructorpublicStudent(Stringfullname){this.name=fullname;}}// Main class to test the Student classpublicclassMain1{publicstaticvoidmain(String[]args){// Create an object of the Student classStudents1=newStudent("Momo");// Print the nameSystem.out.println(s1.name);}}
Get fast, easy, secure n8n VPS hosting from $4.99/mo at Hostinger. Automate any workflow using a pre-installed n8n application and no-code customization.
On job as freelancer working with Java, JDK17+, Jenkins, Maven, Docker, K3S, Git, In my spare time I'm trying to blog about something useful(?) or try to hack on things I like.
Automate your code reviews. Catch bugs before your coworkers. Fix security issues in your code. Built to handle large projects, Amazon Q Developer works alongside you from idea to production code.
Explore a trove of insights in this engaging article, celebrated within our welcoming DEV Community. Developers from every background are invited to join and enhance our shared wisdom.
A genuine "thank you" can truly uplift someone’s day. Feel free to express your gratitude in the comments below!
On DEV, our collective exchange of knowledge lightens the road ahead and strengthens our community bonds. Found something valuable here? A small thank you to the author can make a big difference.
Top comments (2)
Why not using a record; is easier:
ok i'll remind it thank you so much for the suggestion