Java is one of the most popular programming languages. It is an object-oriented programming language which means that we can create classes, objects, and many more. It also supports inheritance, polymorphism, encapsulation, and many more. It is used in all applications starting from mobile applications to web-based applications. Classes are defined as the blue-print or template from which we can create objects and objects are the instances of the class which consist of states and behaviors.
- First, define a class with any name ‘SampleClass’ and define a constructor method.
- The constructor will always have the same name as the class name and it does not have a return type.
- Constructors are used to instantiating variables of the class.
- Now, using the constructors we can assign values.
- After the constructor method, implement a function that returns the value of any variables.
- Now in the main function create an object using the ‘new’ keyword. If there is no user-defined constructor of the class, then the default constructor of the class is called else when the object is created the user-defined constructor is called as per the type and number of parameters matched with the constructor of the class.
- We can call the above-declared function using the object.
- At last print the value from the function using the System.out.println() statement.
- Once you are done with the implementation run the program and will get the output.
The company name is Apple The configuration is i5 Its Cost is 50000 Its operating System IOS
Attention reader! Don’t stop learning now. Get hold of all the important Java Foundation and Collections concepts with the Fundamentals of Java and Java Collections Course at a student-friendly price and become industry ready. To complete your preparation from learning a language to DS Algo and many more, please refer Complete Interview Preparation Course.